import java.util.Scanner;
public class aritmetik {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
int tal1, tal2, result;
System.out.print("Enter a number: ");
tal1 = keyboard.nextInt();
System.out.print("Enter another number: ");
tal2 = keyboard.nextInt();
System.out.println("How much is: " +tal1 + "+" +tal2);
result = keyboard.nextInt(tal1 + tal2);
if(tal1 + tal2 == result){
System.out.println("The answer was correct!");
}else{
System.out.println("The answer was wrong!");
}
}
}
In future purposes I will add some kind of a loop (when I´ve learned a bit about it) and asking the user again and again if the answer is wrong. But for now I just want this code to work.
Something is wrong with the If statement, dont really now what but I get this error message:
Exception in thread "main" java.util.InputMismatchException: For input string: "8"
at java.util.Scanner.nextInt(Scanner.java:2097)
at aritmetik.main(aritmetik.java:16)