Hello /g/.
I have been trying to fix this code for an hour since i woke up.
No clue what's wrong with it, it just doesn't seem to be working.
Please help.
>Problem:
I run it and everything works as it should, only problem is that it println's AFTER user input, rather than BEFORE.
>code:import java.util.Random;
import java.util.Scanner;
public class Math_Master {
public static void main(String[] args) {
Random r = new Random();
Scanner s = new Scanner(System.in);
int op = 0;
int a, b;
int I;
int result;
for (int t = 1; t != 10; t++){
a = r.nextInt(10);
b = r.nextInt(10);
I = s.nextInt();
switch (op){
case 0:
result = a + b;
System.out.println(a + " + " + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//subtraction
case 1:
result = a - b;
System.out.println(a + " - " + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//division
case 2:
result = a / b;
System.out.println(a + " / " + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//multiplication
case 3:
result = a * b;
System.out.println(a + " * " + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//error message
default:
System.out.println("programming is fucked");
}
}
}
}
>inb4 - not you personal tech company
never said you were, just trying to fix this broken code.
import java.util.Random;
import java.util.Scanner;
public class Math_Master {
public static void main(String[] args) {
Random r = new Random();
Scanner s = new Scanner(System.in);
int op = fag;
int a, b;
int I;
int result;
for (int t = 1; t != 10; t++){
a = r.nextInt(10);
b = r.nextInt(10);
I = s.nextInt();
switch (op){
case 0:
result = a + b;
System.out.println(a + " + " + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//subtraction
case 1:
result = a - b;
System.out.println(a + " - " + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//division
case 2:
result = a / b;
System.out.println(a + " / " + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//multiplication
case 3:
result = a * b;
System.out.println(a + " * " + b + "=");
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//error message
default:
System.out.println("programming is fucked");
}
}
}
}
>>60718468
Damn that's some mighty fine unreadable code you got there.
import java.util.Random;
import java.util.Scanner;
public class Math_Master {
public static void main(String[] args) {
Random r = new Random();
Scanner s = new Scanner(System.in);
int op = 0;
int a, b;
int I;
int result;
for (int t = 1; t != 10; t++){
a = r.nextInt(10);
b = r.nextInt(10);
I = s.nextInt(); // NIGGER THIS IS WHY!!!!!!!
switch (op){
case 0:
result = a + b;
System.out.println(a + " + " + b + "=");
/////PUT IT HERE
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//subtraction
case 1:
result = a - b;
System.out.println(a + " - " + b + "=");
////// AND HERE
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//division
case 2:
result = a / b;
System.out.println(a + " / " + b + "=");
/////// AND HERE
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//multiplication
case 3:
result = a * b;
System.out.println(a + " * " + b + "=");
//////// HERE TO YOU RETARDED DICK-HEAD
System.out.println( (I == result ? "correct" : "incorrect.\nThe correct answer was: " + result));
break;
//error message
default:
System.out.println("programming is fucked");
}
}
}
}
>>60718941
thanks anon.
>>60718468
step 1: install intellij
step 2: run you code in intellij
step 3: place debug marks at various lines to insepct variable values.
step 4: correct your simpleton code.
>>60718468
is this a new meme? you have been posting this shitty code for days, if you havent fixed your faggot homework by now just give up, even if you accidentally manage to mass your courses no one wants to work with a fucking idiot that cant figure things out for himself