Thread has been deleted
Last comment
Help with Java PLZ
s1mple | 
Colombia el1teman 
import java.util.*; public class Exercise2 { public static void main(String[] args) { int input; int multiply; int exitInput; Random myRandomNumber = new Random(); Scanner scan = new Scanner(System.in); int myOneDigitNumber = Math.abs(myRandomNumber.nextInt() % 10); int myOneDigitNumber2 = Math.abs(myRandomNumber.nextInt() % 10); multiply = myOneDigitNumber * myOneDigitNumber2; System.out.println("How much is " + myOneDigitNumber + " times " + myOneDigitNumber2 + " ?"); input = scan.nextInt(); if (input == -1) System.exit(-1); while (input != multiply) { System.out.println("No. Please try again.\n"); System.out.println("How much is " + myOneDigitNumber + " times " + myOneDigitNumber2 + " ?"); input = scan.nextInt(); } if (input == multiply) { System.out.println("Very good!"); } } } How would i make this program, keep repeating whole code so its a training game and you can quit it by typing -1
2019-02-12 22:19
#1
 | 
Poland agathacs 
why you ask here
2019-02-12 22:20
#2
Spain rmkx 
Why do you have a main inside a class?
2019-02-12 22:22
#4
s1mple | 
Colombia el1teman 
its weirdly copied out
2019-02-12 22:23
#8
Spain rmkx 
Oh, okay. Just do as #3, do-while, but you have to define the variables before so you don't get random errors.
2019-02-12 22:24
#5
s1mple | 
Colombia el1teman 
wait-
2019-02-12 22:24
#3
f0rest | 
Bulgaria squezzi 
do-while
2019-02-12 22:22
#6
 | 
Norway bruhfessor 
ugly code ;(, you should use methods at least
2019-02-12 22:25
bro still learning
2019-02-12 22:26
Check if string "-1" was typed, not int -1.
2019-02-12 22:24
#9
s1mple | 
Colombia el1teman 
no if i press -1 for input it quits the program, but the program is for calculation game and i want it to keep asking question after if the answer was correct or correct after multiple tries
2019-02-12 22:26
#11
FalleN | 
India GalexE 
import java.util.*; public class Exercise2 { public static void main(String[] args) { int input; int multiply; int exitInput; Random myRandomNumber = new Random(); Scanner scan = new Scanner(System.in); int ans=0; while(ans!=-1) { int myOneDigitNumber = Math.abs(myRandomNumber.nextInt() % 10); int myOneDigitNumber2 = Math.abs(myRandomNumber.nextInt() % 10); multiply = myOneDigitNumber * myOneDigitNumber2; System.out.println("How much is " + myOneDigitNumber + " times " + myOneDigitNumber2 + " ?"); input = scan.nextInt(); if (input == -1) System.exit(-1); while (input != multiply) { System.out.println("No. Please try again.\n"); System.out.println("How much is " + myOneDigitNumber + " times " + myOneDigitNumber2 + " ?"); input = scan.nextInt(); } if (input == multiply) { System.out.println("Very good!"); } System.out.println("Enter -1 to exit and any other key to continue"); ans=scan.nextInt(); } } } Here you go man In stead of taking separate input you may even add if else break condition inside the while loop for entry of input as -1.
2019-02-12 22:29
but it doesnt start over
2019-02-12 22:31
#14
FalleN | 
India GalexE 
It will Copy paste I did it myself and it's working!
2019-02-12 22:32
OH WAIT OMEGALUL IT WORKS, wow lemme read and understand how
2019-02-12 22:33
wow thanks a lot actually, it's pretty smart to make that fuck
2019-02-12 22:36
india tech support her?
2019-02-12 22:38
#12
f0rest | 
Bulgaria squezzi 
do { System.out.println("How much is " + myOneDigitNumber + " times " + myOneDigitNumber2 + " ?"); input = scan.nextInt(); if (input != multiply) System.out.println("No. Please try again.\n"); if (input == multiply) { System.out.println("Very good!"); } while(input != -1); Check the while condition, it must throw a "false"result. I often get confused by do-while loops
2019-02-12 22:33
I wanted to try while input =! -1 but I have to put it before the code asks the question about the answer to certain product and input initialized at that moment
2019-02-12 22:34
#19
 | 
Denmark RandomDane 
I would put everything into the while loop, but dunno
2019-02-12 22:44
Yes I wanted to but I needed input to be initialized and input is the answer to the question and before I cannot
2019-02-12 22:48
#22
 | 
Denmark RandomDane 
Meh. Dunno :C
2019-02-12 22:53
Indian guy helped me lot
2019-02-12 23:27
try do{ ... ... }while(input != -1);
2019-02-12 22:47
Bump
2019-02-12 23:30
Why bump, it's fixed
2019-02-12 23:33
Sorry didnt realize
2019-02-12 23:33
Use an infinite for loop like for(;;) then break out of the loop if input is -1
2019-02-12 23:35
Login or register to add your comment to the discussion.