JAVA Make Code able to copy Multiplication Table Maker Purpo

JAVA

Make Code able to copy.

Multiplication Table Maker

Purpose: to provide an exercise using arrays, methods, and control statements.

When you were learning how to do multiplication, perhaps you memorized a multiplication table, which displayed various results calculated from multiplying the row value by the column value. You are to create a Java application in which your main() will call a method, makeArray(), passing an int for the size of the table to be created (as it is “square”, the number of rows and number of columns are the same.) This method will create a multiplication table in a two-dimensional array by multiplying row/column pairs and then return the array to your main(). Your main() will then call a second method, printArray(), passing the two dimensional array to it. This second called method will print the title containing the table range and then loop through the array, displaying the numbers 1 through 9 across the top row, and the numbers 1 through 9 down the first column, with the results of multiplying any row/column pair displayed at the intersection of that row and column. Separate numbers by tab characters. Use of “%2d” as decimal formatting with printf() will align numbers (up to 99!) correctly. To reiterate: the method, makeArray(), will take an int as a parameter and will return a two dimensional array of int. The method, printArray(), will take a two-dimensional array of int as a parameter and return void. You must call the methods given here and you must pass appropriate values to the parameters, as stated, in order to get any credit. Your resulting table should look like the following, including the title and spacing: Multiplication Table of 1\'s Through 9\'s

1 2 3 4 5 6 7 8 9

2 4 6 8 10 12 14 16 18

3 6 9 12 15 18 21 24 27

4 8 12 16 20 24 28 32 36

5 10 15 20 25 30 35 40 45

6 12 18 24 30 36 42 48 54

7 14 21 28 35 42 49 56 63

8 16 24 32 40 48 56 64 72

9 18 27 36 45 54 63 72 81

Display the table using the maximum value entered as the upper limit for both rows and columns, and be sure to submit your program output displaying results as in the example shown below: Be sure to print the title, as shown, indicating the size of the table and print blank lines between tables. Remember to use good form in your code (indentation, spacing, etc.) as indicated in class. Pay close attention to sections on passing arrays to methods, on returning arrays from methods, and on two-dimensional arrays. Also please note that all of your methods must be static, as we are not defining our own objects in this lab.

Solution

MultiplicationTable.java

import java.util.Scanner;

public class MultiplicationTable {

   public static void main(String[] args) {
       //Declaring variables
       int number ;
       int arr[][];
      
       // Scanner class object is used read the inputs entered by the user
       Scanner sc = new Scanner(System.in);

       //This loop continue to execute until user enters 0 as input.
       while(true)
       {
           //getting the size of the 2-Dimensional array entered by the user
           System.out.print(\"Please Enter the Maximum table Size (0 to Quit):\");
           number = sc.nextInt();
          
           /* checking whether the number is zero or not
           * If not Zero then call the methods
           * If zero,then program will exit.
           */
if(number!=0)
{
   //Calling the method by passing the number as input
           arr = makeArray(number);
          
           //Calling the method by passing the array as input.
           printArray(arr);
           continue;
}    
else
break;

       }
   }

   //This will print the Array elements on the console
   private static void printArray(int[][] arr) {
      
       //displaying the array in the form of table
       System.out.println(\"Multiplication Table of 1\'s Through \" + arr.length+ \"\'s\");
       for (int i = 0; i < arr.length; i++) {
           for (int j = 0; j < arr[0].length; j++) {
               System.out.printf(\"%8d\", arr[i][j]);
           }
           System.out.println(\" \");
       }
       System.out.println(\"\ \");
   }

   /* this method will create the 2-Dimensional array and populate it will multiplication values
   * Params : number of integer type
   * Return : 2-D array
   */
   private static int[][] makeArray(int number) {
       int array[][] = new int[number][number];
       for (int i = 1; i <= number; i++) {
           for (int j = 1; j <= number; j++) {
               array[i - 1][j - 1] = i * j;
           }
       }
       return array;
   }

}

_________________________________________

Output:

Please Enter the Maximum table Size (0 to Quit):4
Multiplication Table of 1\'s Through 4\'s
1 2 3 4
2 4 6 8
3 6 9 12
4 8 12 16


Please Enter the Maximum table Size (0 to Quit):5
Multiplication Table of 1\'s Through 5\'s
1 2 3 4 5
2 4 6 8 10
3 6 9 12 15
4 8 12 16 20
5 10 15 20 25


Please Enter the Maximum table Size (0 to Quit):3
Multiplication Table of 1\'s Through 3\'s
1 2 3
2 4 6
3 6 9


Please Enter the Maximum table Size (0 to Quit):0

____________________________________Thank You

JAVA Make Code able to copy. Multiplication Table Maker Purpose: to provide an exercise using arrays, methods, and control statements. When you were learning ho
JAVA Make Code able to copy. Multiplication Table Maker Purpose: to provide an exercise using arrays, methods, and control statements. When you were learning ho
JAVA Make Code able to copy. Multiplication Table Maker Purpose: to provide an exercise using arrays, methods, and control statements. When you were learning ho

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site