#java #compiler-errors
#java #ошибки компилятора
Вопрос:
У меня возникла эта проблема с запуском простой программы из Notepad с использованием Java. Проблема в том, что в ошибке говорится что-то вроде: ошибка: строка не может найти символ: 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) amp;amp;
(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) amp;amp;
(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. Я вообще не вижу
char
в вашем коде. Я что-то упустил?2. Я не получаю ошибку компиляции, копируя / вставляя ваш код в Eclipse и компилируя.
3. В вашем коде нет символов. Отредактируйте свой вопрос, пожалуйста.
Ответ №1:
Попробуйте использовать input.next()
вместо input.nextLine()