import java.util.Scanner; public class aritmetik { public static void main(String[] args) { Scanner keyboard = new Scanner(System.in); int resultat, tal1, tal2; System.out.print("Enter a digit: "); tal1 = keyboard.nextInt(); System.out.print("Enter another digit: "); tal2 = keyboard.nextInt(); System.out.println("How much is: " +tal1 + "+" +tal2 +"?"); resultat = keyboard.nextInt(); if(resultat == tal1 + tal2){ System.out.println("Your answer was right!"); }else{ System.out.println("Your answer was wrong."); } } }
Hey,
I'm a total newbie to Java programming. Itīs a course i'm taking in the university. Itīs actually a lot of fun (when it works) not so fun when it doesn't
Anyway I've managed to program whats above, and it works fine. But I would like to tweak it a bit. I want to the program, say if you answer right: the program asks you if you would like to continue doing the same process again (but entering other digits) and if you answer wrong it will say: wrong answer, try again and let you enter the sum once more until you are right.
I have watched I think 5 different youtube-videos about loops. I think a Do loop would be the case for me. But I have no idea how to implement it. Could someone be helpful and show me a bit for starters so that I have something to go on with
Thanks!