【问题标题】:Java, compiling error?Java,编译错误?
【发布时间】:2016-10-09 00:41:38
【问题描述】:

我在使用 Java 从 Notepad++ 运行简单程序时遇到了这个问题。问题是它在错误中说诸如错误:字符串找不到符号:char c = (char)i。程序如下:

import java.util.Scanner; //Scanner import

public class q1 { //public class

    public static void main(String[]args) { //main class

        String word1;
        String word2;
        String word3; 

        Scanner input = new Scanner(System.in);

        System.out.println("Please enter the first word!"); //Asking user for first word
        word1 = input.nextLine();//User input

        System.out.println("Please enter the second word!"); //Asking user for second word
        word2 = input.nextLine();//User input

        System.out.println("Please enter the third word!"); //Asking user for third word
        word3 = input.nextLine();//User input

        if ((word1.compareToIgnoreCase(word2)<0) &&
            (word1.compareToIgnoreCase(word3)<0)) //if first word comes first accordingly with return value...
        {
            System.out.println(word1); //display the first word
            //IgnoreCase is used so that program works even with capitalized words
            if (word2.compareToIgnoreCase(word3) < 0) //then, if the second word's return value is less than zero....
            {
                // then display second word then the third word.
                System.out.println(word2);
                System.out.println(word3);
            } else //if not,
            {
                System.out.println(word3);//display the third word, then the second.
                System.out.println(word2);
            }
        } else if ((word1.compareToIgnoreCase(word2) > 0) &&
                   (word2.compareToIgnoreCase(word3) < 0)) // if the first word's return value is greater than 0
        // and if the second word's return value is less than 0...
        {
            System.out.println(word2); //display the second word
            if (word1.compareToIgnoreCase(word3) < 0) //next, if the first word's return value is 0, then...
            {
                //display word 1 and then word 3
                System.out.println(word1);
                System.out.println(word3);
            } else
            {
                //if not, then display word 3 then word 1
                System.out.println(word3);
                System.out.println(word1);
            }
        } else //if none of the word 1 or word 2's return values are....
        {
            System.out.println(word3);// then display word 3 first...
            if (word1.compareToIgnoreCase(word2) < 0) //then if word 1 has a return value of less than 0 than that of word 2
            {
                // then display word 1 and word 2 next
                System.out.println(word1);
                System.out.println(word2);
            } else {
                //otherwise, display word 2 and word 1...
                System.out.println(word2);
                System.out.println(word1);
            }
        }
    }       
}

有什么问题?

【问题讨论】:

  • 我在你的代码中根本看不到char。我错过了什么吗?
  • 复制/粘贴您的代码到 Eclipse 并编译时没有编译错误。
  • 您的代码中没有字符。请编辑您的问题。

标签: java compiler-errors


【解决方案1】:

尝试使用input.next() 而不是input.nextLine()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-12
    • 2014-04-26
    • 2018-07-11
    • 1970-01-01
    • 1970-01-01
    • 2015-07-01
    相关资源
    最近更新 更多