好的,有一些帮助我重做代码,但当我尝试comppile我不断收到错误。错误:非法开始表达(第17行)......箭头指向joption代码的末尾。我不明白它想要我做什么。下面是代码:
public class Project0 {
public static void main(String[] args) {
char uppercase = 'E';
char lowercase = 'e';
int isLower=0;
int isUpper =0;
String inputWord;
inputWord = JOptionPane.showInputDialog(null, "Please enter a sentence");
while (!inputWord.equals("stop"))
{
isLower = wordIsThere(inputWord, lowercase);
isUpper = wordIsThere(inputWord, uppercase);
JOptionPane.showMessageDialog(null, ("Number of " +inputWord+ " Lower: " +isLower+ "Upper: " +isUpper+));
inputWord = JOptionPane.showInputDialog(null, "Please enter a sentence or enter stop");
isUpper=0;//reset
isLower=0;
}//while ends here.
System.out.println("ENDS");
}//main
public static int wordIsThere(String findMe, char theLetter)
{
int count=0;
for (int i=0; i<findMe.length(); i++ )
if (findMe.charAt(i) == theLetter)
count++;
return count;
}
}
答案 0 :(得分:4)
从+
方法
showMessageDialog
运算符
JOptionPane.showMessageDialog
(null, ("Number of " +inputWord+ " Lower: " +isLower+ "Upper: " +isUpper));
^
答案 1 :(得分:2)
在字符串连接结束时你有一个额外的+
,因此Java期待添加其他内容。
// Here
("Number of " +inputWord+ " Lower: " +isLower+ "Upper: " +isUpper+)
删除+
或在串联中添加其他内容。