Hey every one I just need some help with formatting some code, I'm supposed to make a table, however I can't seem to get the alignment correct. So far this is the code I've gotten:
public class assignment2 {
public static void main(String[] args) {
int line = 0;
int down = 0;
int num =0;
for (line = 1; line < 21; line++){
System.out.print(" " + line ); //prints the numbers across with 5 spaces
}
System.out.print("\n"); //moves the compiler to a new line, same thing as System.out.println
for (down = 1; down <= 20; down++) { //prints out the numbers down with 4 spaces to the first number
System.out.print(down + " ");
for (int i = 1; i <= 20; i++){ //Counter to stand in place for the x-axis numbers
num = i % down;
if (num != 0) {
System.out.print(" "); // 5 spaces, checks to see if the number are multiples of each other
if (i > 9){
System.out.print(" " ); //1 spaces, also aligns the numbers going diagonally
}
} else {
if (i >= 10){
if (i % 2 == 0 ) {
System.out.print("E"+" "); // 6 spaces
} else
System.out.print("O"+ " "); // 6 spaces
} else {
if (i % 2 == 0 ) {
System.out.print("E"+" "); // 5 spaces
} else {
System.out.print("O"+ " "); // 5 spaces
}
}
}
if (down >=2){
System.out.print(" "); // 1 space
}
if (i == 20){
System.out.print("\r\n");
}
}
}
}
So far the text looks like this: Screen shot of display with code playing. Any help would be appreciated, it you can point in the right direction and point out any mistakes I've done in the code it would be great appreciated!