Question

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:

  chapter8SampleOutput.png

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 display the array: public static void printMultiplicationTable(int table[ ][ ], int x, int y)

You must load the table array with products of the factors. For example:

In Figure 1 above, the 5 x 5 array is loaded with the products for the times tables from 4 to 8

In Figure 2 above, the 2 x 2 array is loaded with the products for the times tables from 5 to 6

GENERAL RESTRICTIONS FOR ALL QUIZZES, MIDTERM AND FINAL EXAM

No global variables

No infinite loops, examples include:

for(;;)

while(1)

while(true)

do{//code}while(1);

No break statements to exit loops

No labels or go-to statements

If you violate any of these restrictions, you will automatically get a score of ZERO!

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

Program:

import java.util.Scanner;

public class MultiplyProgram

{

public static void loadArray(int table[][], int x, int y)

{

        for(int r=x,p=0; p<=table.length-1; r++, p++)

        {

            for(int c=x, q=0; q<=table.length-1; c++,q++)

               table[p][q] = r*c;

        }

}

public static void printMultiplicationTable(int table[][], int x, int y)

{

       System.out.print("        ");

       for(int r=x; r<=y; r++)

           System.out.print(r+"\t");

           System.out.println("\n----------------------------------------------------");

         for(int r=x,p=0; p<=table.length-1; r++, p++)

         {

            System.out.print(r+"\t");

                for(int q=0; q<=table.length-1; q++)

                       System.out.print(table[p][q]+"\t");

           System.out.println();

         }

}

public static void main(String[] args)

{

       Scanner s = new Scanner(System.in);

       System.out.print("Enter the starting value \n");

       int x = s.nextInt();

       System.out.print("Enter the ending value \n");

       int y = s.nextInt();

       int m;

       m = y-x+1;

       int[][] table= new int[m][m];

       loadArray(table, x, y);

       printMultiplicationTable(table, x, y);

       s.close();

   }

}

Output:

Enter the starting value Enter the ending value 4 6 16 20 24 28 32 20 25 30 35 40 24 30 36 42 28 35 42 49 56 32 40 48 56 6Enter the starting value Enter the ending value 6 25 30 30 36 6

Add a comment
Know the answer?
Add Answer to:
Write a program which: Prints out the Multiplication Table for a range of numbers (positive integers)....
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: 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...

  • 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...

  • 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...

  • 1. Write a program that prompts the user to enter three integers and display the integers...

    1. Write a program that prompts the user to enter three integers and display the integers in non-decreasing order. You can assume that all numbers are valid. For example: Input Result 140 -5 10 Enter a number: Enter a number: Enter a number: -5, 10, 140 import java.util.Scanner; public class Lab01 { public static void main(String[] args) { Scanner input = new Scanner(System.in);    } } ---------------------------------------------------------------------------------------------------------------------------- 2. Write a program that repeatedly prompts the user for integer values from...

  • Write an algorithm that prints a multiplication table for up to 9 times 9. As an...

    Write an algorithm that prints a multiplication table for up to 9 times 9. As an example, a multiplication table up to 3 times 3 looks like: 4 6 How might you change your algorithm to allow the user to specify the size of the table?

  • Write a program that instantiates an array of integers named scores. Let the size of the...

    Write a program that instantiates an array of integers named scores. Let the size of the array be 10. The program then first invokes randomFill to fill the scores array with random numbers in the range of 0 -100. Once the array is filled with data, methods below are called such that the output resembles the expected output given. The program keeps prompting the user to see if they want to evaluate a new set of random data. Find below...

  • Reverse.cpp Write a program that reads in a series of positive integers terminted by a -1,...

    Reverse.cpp Write a program that reads in a series of positive integers terminted by a -1, e.g.           73 95 61 21 90 85 14 78 -1 The values should be stored in an array.   The program then prints the values in reverse order as well as the average (to one decimal place). For example, Please enter the integers: 73 95 61 21 90 85 14 78 -1 The values in reverse order are         78   14   85   90   21...

  • 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 (...)        {           ...

  • 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...

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