Question

Write a program which: 1. Prints out the Multiplication Table for a range of numbers (positive...

Write a program which:

1. Prints out the Multiplication Table for a range of numbers (positive integers). • Prompts the user for a starting number: say 'x' • Prompts the user for an ending number: say 'y' • Prints out the multiplication table of 'x' up to the number 'y'

SPECIFIC REQUIREMENTS

1. You must use the following method to load the array: public static void loadArray(int table[][], int x, int y) 2. You must use the following method to display the array: public static void printMultiplicationTable(int table[][], int x, int y) 3. You must load the table array with products of the factors. For example: the 5 x 5 array is loaded with the products for the times tables from 5 to 8

the 2 x 2 array is loaded with the products for the times tables from 5 to 6

1. No infinite loops, examples include: a. for(;;) b. while(1) c. while(true)

d. do{//code}while(1); 2. No break statements to exit loops

please write the code in the programming language java

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Please comment and explain the following part ==> " ........You must load the table array with products of the factors. For example: the 5 x 5 array is loaded with the products for the times tables from 5 to 8. the 2 x 2 array is loaded with the products for the times tables from 5 to 6...... "


public class MultiplicationTable {

   public static int MAX_SIZE = 1000;
  
   public static void loadArray(int[][] table, int x, int y) {
       for (int i=0; i<=x; i++) {
           for (int j=0; j<=y; j++) {
               table[i][j] = i*j;
           }
       }
   }
  
   public static void printMultiplicationTable(int[][] table, int x, int y) {
       for (int j=0; j<=y; j++) {
           System.out.println(x + " x " + j + " = " +table[x][j]);
       }
   }
  
   public static void main(String[] args) {
       int[][] table = new int[MAX_SIZE][MAX_SIZE];
       loadArray(table, 5,18);
       printMultiplicationTable(table, 5, 18);
   }
}

Add a comment
Know the answer?
Add Answer to:
Write a program which: 1. Prints out the Multiplication Table for a range of numbers (positive...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a program which: Prints out the Multiplication Table for a range of numbers (positive integers)....

    Write a program which: Prints out the Multiplication Table for a range of numbers (positive integers). Prompts the user for a starting number: say 'x' Prompts the user for an ending number: say 'y' Prints out the multiplication table of 'x' up to the number 'y' Sample outputs include:    SPECIFIC REQUIREMENTS You must use the following method to load the array: public static void loadArray(int table[ ][ ], int x, int y) You must use the following method to...

  • In Java Write a program that reads an arbitrary number of 25 integers that are positive...

    In Java Write a program that reads an arbitrary number of 25 integers that are positive and even. The program will ask the user to re-enter an integer if the user inputs a number that is odd or negative or zero. The inputted integers must then be stored in a two dimensional array of size 5 x 5. Please create 3 methods: 1. Write a method public static int sum2DArray( int [1] inputArray ) The method sums up all elements...

  • In C++ The Multiplication Program Step 1: Write a program that stores a multiplication table in...

    In C++ The Multiplication Program Step 1: Write a program that stores a multiplication table in a 9-by-9 two-dimensional array. Generate the multiplication table with two loops. (So you will have a nested loop that will iterate 9 times and fill the 9x9 array with the values.) Step 2: Display the table for the user to see it. a 9x9 table Step 3: Create a function that returns the product of two numbers between 1 and 9by looking up the...

  • 1.Write code for a Java method, printArray, that takes an int array as parameter and prints...

    1.Write code for a Java method, printArray, that takes an int array as parameter and prints it out, one element per line. public static void printArray (int[] values){ Methods that do NOT return a result have “void” as return type. Notice how an array parameter type is passed, int [] }// end printArray 2.Write code for a Java method that takes in as input parameter an integer number, say num, and returns a double array of size num with all...

  • Write a program that prints out multiplication table: 1. In the main loop, it should ask...

    Write a program that prints out multiplication table: 1. In the main loop, it should ask a user to enter a number in the range of 1 to 12. Exit the program upon input out of range (eg., 0 or 13). 2. Output the multiplication table from 1 to 12. Possible output: Enter the number (1-12): 9 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5...

  • In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are...

    In Java* ​​​​​​​ Write a program that reads an arbitrary number of 20 integers that are in the range 0 to 100 inclusive. The program will ask a user to re-enter an integer if the user inputs a number outside of that range. The inputted integers must then be stored in a single dimensional array of size 20. Please create 3 methods: 1. Write a method public static int countEven(int[] inputArray) The method counts how many even numbers are in...

  • Create a class called Play that has an InputReader as an instance variable. Be sure to...

    Create a class called Play that has an InputReader as an instance variable. Be sure to initialize it in the constructor. The class has two methods. Write a method with this signature: Write a method with this signature: public void stringPlay() The method prompts the user for a string, reads it in, and then displays the string as many times as the length of that string. The output string should be formatted with the first letter uppercase and the rest...

  • Write a while loop that prints all positive numbers that are divisible by 10 and less...

    Write a while loop that prints all positive numbers that are divisible by 10 and less than a given number n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90. import java.util.Scanner; public class PositiveLess {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        System.out.print("n: ");        int n = in.nextInt();        ...        while (...)        {           ...

  • Write a JAVA program that has 2 methods with the same name: printCaps(String input) prints the...

    Write a JAVA program that has 2 methods with the same name: printCaps(String input) prints the input in capital letters, printCaps(String input, int num) prints in capital letters the specified number of times on a new line: public static void printCaps(String input) public static void printCaps(String input, int num)

  • Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array...

    Which of the following are valid array declarations? a. int[] array- new int[10]; b. double [array double[10]; c. charl charArray "Computer Science"; None of the above Analyze the following code: class Test public static void main(Stringl] args) System.out.println(xMethod(10); public static int xMethod(int n) System.out.println("int"); return n; public static long xMethod(long n) System.out.,println("long"); return n The program displays int followed by 10 The program displays long followed by 10. The program does not compile. None of the above. tions 3-4 are...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT