-
Ternary Code Help
I'm still a little confused on the question mark and colon sign. I've already seen threads on how to use it but using it in this array is a little more confusing. I would like it if someone could recode this method using ifs and elses.
Code:
private void drawTurtle() {
for (int i = 0; i < 20; i++) {
for (int j = 0; j < 20; j++)
System.out.print(floor[i][j] ? "* " : " ");
System.out.println();
}
}
-
Re: Ternary Code Help
Code:
System.out.println(foo ? bar : baz);
means the same as
Code:
String toPrint;
if(foo) {
toPrint = bar;
} else {
toPrint = baz;
}
System.out.println(toPrint);
You can try this substitution with your code. One thing to watch is how the braces work: use braces with all structures, even one line for loops.
-
Re: Ternary Code Help
Using if-else statement it will be like what pbrockway2 said. Sorry I couldn't delete my post :D
-
Re: Ternary Code Help
Moved from Advanced Java.
db