[英]Java, compiling error?
我在使用 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);
}
}
}
}
有什么問題?
嘗試使用input.next()
而不是input.nextLine()
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.