My code contains a switch statement, and in all cases there are else statements. They are all quite short, so I thought about code compression, turning them into conditional statements. The format I was going to was ...
System.out.printf( (conditional-Statement ) );
Here is my if else statement for one of the cases ...
if (count == 1) {
System.out.printf("%3d", count);
} else {
System.out.printf("%11d", count);
}
Sort of...
System.out.print((count == 1) ? count : " " + count);
does not create syntax errors
but it all messed up when I did it ...
System.out.printf((count == 1) ? "%3d", count : "%11d", count);
Am I trying to do this?
source
share