Main.java:53: ошибка: несовместимые типы: строку невозможно преобразовать в
int
Строка 53 — это оператор if ниже, введенный пользователем.
Код: Выделить всё
if(i.puzzle2(name2,userInput)){
Scanner puz3name = new Scanner(System.in);
System.out.println("you have 3 chances to guess a number");
int firstnum= puz3name.nextInt();
System.out.println(i.puzzle2(name2,firstnum));
Код: Выделить всё
public boolean puzzle1(String name, String userInput) {
//examine the conditions for puzzle 1
//if the user answers correctly the process continues
System.out.println("checking...");
if (name.substring(0,1).equals(userInput.substring(0,1))){
return true;
}
return false;
}
public boolean puzzle2(String name, int userInput) {
//examine the conditions for puzzle 2
//if the user answers correctly the process continues
int lastdig = userInput%10;
int sqrname = name.length()*name.length();
if(sqrname%10==lastdig)
return true;
else return false;
}
public boolean puzzle3(String name, int userInput) {
//examine the conditions for puzzle 3
//if the user answers correctly the process continues
if (userInput==(name.length()+ 10) / 3)
return true;
else if (userInput>(name.length()+ 10) / 3){
System.out.println("Your guess is too high");
return false;
}
else if (userInput
Подробнее здесь: [url]https://stackoverflow.com/questions/79123977/stuck-on-how-to-write-this-if-statement-with-a-method[/url]
Мобильная версия