Java,编译错误?

时间:2016-10-09 00:41:38

标签: java compiler-errors

我在使用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);
            }
        }
    }       
}

有什么问题?

1 个答案:

答案 0 :(得分:0)

尝试使用input.next()代替input.nextLine()