Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Create a Java console program that prompts a user to enter a number. The program

ID: 3817365 • Letter: C

Question

Create a Java console program that prompts a user to enter a number. The program uses the input value to calculate and list the products of two numbers up to the entered number. For instance, if a user has entered 3, the program calculates the products between two numbers (e.g., 1x1, 1x2, 1x3, 2x1, 2x2, 2x3, 3x1, 3x2, and 3x3), stores the products into a two-dimensional array, and list the multiplied numbers. It should resemble the following:

C:JavaCode >Java Exam04TomJones Enter a positive integer: 3 11 2246 2 3…36 3-369 >i 2-246 123

Explanation / Answer

Example04TomJones.java

import java.util.Scanner;


public class Example04TomJones {

  
   public static void main(String[] args) {
       Scanner scan = new Scanner(System.in);
       System.out.println("Enter a positive integer: ");
       int n = scan.nextInt();
       int a[][] = new int[n][n];
       for(int i=1; i<=n; i++){
           for(int j=1; j<=n; j++){
               a[i-1][j-1] = i * j;
           }
       }
       System.out.print(" ");
       for(int i=1; i<=n; i++){
           System.out.print(i+" ");
       }
       System.out.println();
       System.out.print(" ");
      
       for(int i=1; i<=n; i++){
       System.out.print("--- ");
       }
       System.out.println();
       for(int i=1; i<=n; i++){
           System.out.print(i+" ");
           for(int j=1; j<=n; j++){
               System.out.print(a[i-1][j-1]+" ");
           }
           System.out.println();
       }
   }

}

Output:

Enter a positive integer:
3
   1   2   3  
   ---   ---   ---  
1   1   2   3  
2   2   4   6  
3   3   6   9