The user inputs two numbers on the command line, and the program generates a 2-dimensional array of a multiplication table.
import java.util.*;
/**
*
* @author James
*/
public class multiplication {
public static void main(String[] args) {
Scanner sin = new Scanner(System.in);
int nNum1, nNum2;
// this becomes the number of rows
System.out.print("Enter a number: ");
nNum1 = sin.nextInt();
// this becomes the number of cols
System.out.print("Enter another number: ");
nNum2 = sin.nextInt();
System.out.println("Here you go a " + nNum1 + " by " + nNum2 +
" multiplication table.");
// this array holds a nNum1 * nNum2 multiplication table
double[][] ardMult = new double[nNum1][nNum2];
for (int row=0;row<nNum1;row++) {
for (int col=0;col<nNum2;col++) {
ardMult[row][col] = row+1 * col+1;
System.out.print(ardMult[row][col] + " ");
}
System.out.println();
}
}
}


Sign In
Create Account


Back to top










