Я создал программу, которая запрашивает 3 целых числа для вывода типа треугольника. Все работает и успешно скомпилирован, однако, кажется, та часть, где он запрашивает у пользователя, чтобы увидеть, если они хотят, чтобы цикл снова, интернет-компилятор выдает ошибку:Scanner NoSuchElementException
Exception in thread "main" java.util.NoSuchElementException at java.util.Scanner.throwFor(Scanner.java:838) at java.util.Scanner.next(Scanner.java:1347) at Assignment5.main(Assignment5.java:56)
import java.util.Scanner;
public class Assignment5 {
public static void main (String[]args)
{
for (int a = 0; a < Integer.MAX_VALUE; a++)
{
Scanner userInput = new Scanner(System.in);
Scanner answer = new Scanner(System.in);
int x,y,z;
System.out.println("Enter the sides of the triangle: ");
x = userInput.nextInt();
y = userInput.nextInt();
z = userInput.nextInt();
Tri isos = new Tri(x,y,z);
Tri equal = new Tri(x,y,z);
Tri scalene = new Tri(x,y,z);
// check the equilateral triangle
System.out.println(equal.toString() + " triangle:");
if (equal.is_isosceles())
System.out.println("\tIt is isosceles");
else
System.out.println("\tIt is not isosceles");
if (equal.is_equilateral())
System.out.println("\tIt is equilateral");
else
System.out.println("\tIt is not a equilateral");
if (equal.is_scalene())
System.out.println("\tIt is scalene");
else
System.out.println("\tIt is not scalene");
System.out.println("Would you like to enter values again? (y/n)");
String input = answer.next(); //Exception is thrown from here
if (input.equals("y"))
{
System.out.println("ok");
}
else if(!input.equals("y"))
{
System.out.println("Ok, bye.");
break;
}
}
}
}
Что находится на линии 56? Мне также интересно, зачем вам 2 сканера. –
Строка 56: Строка input = answer.next(); \t \t , если (input.equals ("у")) \t { \t \t System.out.Println ("хорошо"); \t} \t еще если \t { \t \t System.out.println ("Хорошо, до свидания.") (Input.equals ("у")!); \t \t break; \t} – Ryan
Протестировано, и оно отлично работает для меня. – Aneesh