gpt4 book ai didi

java - Java,编译错误?

转载 作者:行者123 更新时间:2023-12-02 11:15:51 25 4
gpt4 key购买 nike

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

关于java - Java,编译错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39938836/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com