[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Can we fix it?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 7
Thread images: 3

File: .jpg (1MB, 5120x3840px) Image search: [Google]
.jpg
1MB, 5120x3840px
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.
>>
File: anon delivers.jpg (100KB, 854x770px) Image search: [Google]
anon delivers.jpg
100KB, 854x770px
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");
}
}
}
}
>>
File: TIFI.jpg (16KB, 272x206px) Image search: [Google]
TIFI.jpg
16KB, 272x206px
>>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
Thread posts: 7
Thread images: 3


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.