need to finish this code. Need ASAP! please help thanks 5 star rating for right
ID: 3553877 • Letter: N
Question
need to finish this code. Need ASAP! please help thanks 5 star rating for right working answer.
public class Lab10a
{
public static void main(String[] args)
{
// Read an integer from the command line
int tableSize = Integer.parseInt(args[0]);
// Create a 2D array of ints to hold the addition table
int table[][] = // [add code here];
// Fill out the table using a nested loop so that
// table[r][c] = r + c
// [add code here]
// Iterate over the table, printing each value
// so that columns align (hint: use a nested loop,
// and printf)
// [add code here]
}
}
When finished, with an input value of 4, the program should print something like:
0 1 2 3
1 2 3 4
2 3 4 5
3 4 5 6
Explanation / Answer
public class Lab10a
{
public static void main(String[] args)
{
// Read an integer from the command line
int tableSize = Integer.parseInt(args[0]);
// Create a 2D array of ints to hold the addition table
int table[][] = new int[tableSize][tableSize];
for(int i=0;i<tableSize;i++){
for(int j=0;j<tableSize;j++){
table[i][j]=i+j;
}
}
for(int i=0;i<tableSize;i++){
for(int j=0;j<tableSize;j++){
System.out.print(table[i][j]+" ");
}
System.out.println();
}
}
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.