-1

好的,有一些帮助我重新编写了代码,但是当我尝试编译时,我不断收到错误消息。错误:表达式的非法开头(第 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; 
  }
      }
4

2 回答 2

4

从方法中删除最后一个+运算符showMessageDialog

JOptionPane.showMessageDialog
   (null, ("Number of " +inputWord+ " Lower: " +isLower+ "Upper: " +isUpper));
                                                                           ^
于 2013-09-25T17:06:50.907 回答
2

+您在字符串连接的末尾有一个额外的内容,因此 Java 期望添加其他内容。

//                                                              Here
("Number of " +inputWord+ " Lower: " +isLower+ "Upper: " +isUpper+)

删除+或添加其他内容到串联中。

于 2013-09-25T17:07:10.533 回答