-
Addition Table?
This is the code for an addition table I made for my class. This prints the table properly, but the teacher said "Your printAdditionTable is printing the whole table itself instead of using a method to do a row and then repeating that method (that row) with a different starting value." I think I need to do a loop, but dont know how would I do this. any help would be appreciated.
Code:
public static void printAddTable (){
int i = 0, j=0;
for (i=0; i<=12; i++) {
for (j=0; j<=12; j++){
System.out.print (i+j+ " ");
}
System.out.println (" ");
}
}
-
Re: Addition Table?
Code:
public static void printRow(int i, int max){
for(int j = 0; j<=max; j++){
System.out.print(i + j + "\t"); /Print entry plus tab char.
}
System.out.println();
}
Something like this for printing a row at a time. You've got the right idea to begin with, just need to create a method to do it.