The code below for TaysiIkaisyys runs well when tested, but gives the error "NoSuchElementException" when locally tested. There doesn't seem to be anything wrong with the code. The error report is very lackluster and hard to interpret.
import java.util.Scanner;
public class TaysiIkaisyys {
public static void main(String[] args) {
Scanner lukija = new Scanner(System.in);
// Toteuta ohjelmasi tähän.
System.out.println("Anna ensimmäinen luku: ");
int luku1 = Integer.parseInt(lukija.nextLine());
System.out.println("Anna toinen luku: ");
int luku2 = Integer.parseInt(lukija.nextLine());
if (luku1 > luku2) {
System.out.println("Suurempi luku: " + luku1);
} else if (luku2 > luku1) {
System.out.println("Suurempi luku: " + luku2);
} else {
System.out.println("Luvut ovat yhtä suuret!");
}
}
}
The code and the exercise name doesn't really appear to be the same. Would it be possible that you were working on incorrect exercise in netbeans?
The NoSuchElementException occurs rarely; it basically means that you were reading more stuff than what tests had been prepared for...