Question

In: Computer Science

Write a Java program named, MultiTable, (MultiTable.java), with the following tasks: Prompt user to input the...

Write a Java program named, MultiTable, (MultiTable.java), with the following tasks:

  • Prompt user to input the maximum number (as integer)
  • Store a multiplication table for all combinations (with some specific eliminations) of value 0 through the maximum number (being entered) into a 2-D array
  • Write a method named printTable to print out the MulitTable, with the following header,
    • public static void printTable(int[][] multitable)
  • In printTable(), when the value of the MultiTable is an odd number, print out Z
  • Must use System.out.printf() for all output functions
  • Sample output:
Please enter positive max. number:5
    0    0    0    0    0    0
    0    Z    2    Z    4    Z
    0    2    4    6    8   10
    0    Z    6    Z   12    Z
    0    4    8   12   16   20
    0    Z   10    Z   20    Z
  • Sample output:
Please enter positive max. number:11
    0    0    0    0    0    0    0    0    0    0    0    0
    0    Z    2    Z    4    Z    6    Z    8    Z   10    Z
    0    2    4    6    8   10   12   14   16   18   20   22
    0    Z    6    Z   12    Z   18    Z   24    Z   30    Z
    0    4    8   12   16   20   24   28   32   36   40   44
    0    Z   10    Z   20    Z   30    Z   40    Z   50    Z
    0    6   12   18   24   30   36   42   48   54   60   66
    0    Z   14    Z   28    Z   42    Z   56    Z   70    Z
    0    8   16   24   32   40   48   56   64   72   80   88
    0    Z   18    Z   36    Z   54    Z   72    Z   90    Z
    0   10   20   30   40   50   60   70   80   90  100  110
    0    Z   22    Z   44    Z   66    Z   88    Z  110    Z

Solutions

Expert Solution

Thanks for the question. Below is the code you will be needing. Let me know if you have any doubts or if you need anything to change. 

If you are satisfied with the solution, please leave a +ve feedback : ) Let me know for any help with any other questions.

Thank You!
===========================================================================

import java.util.Scanner;

public class MultiTable {

    public static void printTable(int[][] multitable) {

        int size = multitable.length;

        for (int row = 0; row < size; row++) {
            for (int col = 0; col < size; col++) {

                if (multitable[row][col] % 2 == 1) {
                    System.out.printf("%5c", 'Z');
                } else {
                    System.out.printf("%5d", multitable[row][col]);
                }
            }
            System.out.println();
        }


    }

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.print("Please enter positive max. number: ");
        int size = scanner.nextInt();

        if (size <= 0) {
            System.out.println("Error: input number cannot be zero or negative.");
            return;
        }

        size+=1;

        int[][] multiTable = new int[size][size];

        for (int row = 0; row < size; row++) {
            for (int col = 0; col < size; col++) {
                multiTable[row][col] = row * col;
            }
        }


        printTable(multiTable);

    }
}

===================================================================


Related Solutions

Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the...
Write a Java program named, TicketSale, (TicketSale.java) with the following tasks: Prompt user to input the number of Adult tickets to purchase Prompt user to input the number of Children tickets to purchase Prompt user to input the number of Senior tickets to purchase Write a method named, ticketCost(), which will be invoked by main() with statement similar to: cost = ticketCost( adults, children, senior ); Ticket costs structure: $15.00 for each adult $10.00 for each child $5.00 for each...
Using Java, write a program named MyAngles that will prompt the user for the measure of...
Using Java, write a program named MyAngles that will prompt the user for the measure of the three sides of a triangle and then reports the measurement of each interior angle of the triangle and the area of the triangle.
Write an error-free Java program to do the following things. Prompt the user to input a...
Write an error-free Java program to do the following things. Prompt the user to input a set of numbers. The numbers represent hourly wages so they will be between 7.25 (peon) and 50 (big boss). The user should be able to input up to 35 numbers but if the user enters 0 then the data input ceases. All of the data that the user enters should be stored in a single array. You do not need to check the input...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter the name of the month he/she was born in (example: September). b) Prompt the user to enter his/her weight in pounds (example: 145.75). c) Prompt the user to enter his/her height in feet (example: 6.5). d) Display (print) a line of message on the screen that reads as follows: You were born in the month of September and weigh 145.75 lbs. and...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user...
IN JAVA PROGRAMMING Write a complete Java program to do the following: a) Prompt the user to enter a six-digit integer. b) Take the integer and break it up into two pieces of three-digits each (make sure you keep the order of digits). c) Display each 3-digit piece on a separate line with a proper message before each piece. For example, if the user enters  450835 as the integer, then the program should display the following output: Right 3-digit piece: 835...
Write a program that uses input to prompt a user for their name and then welcomes...
Write a program that uses input to prompt a user for their name and then welcomes them. Note that input will pop up a dialog box. Enter Sarah in the pop-up box when you are prompted so your output will match the desired output.(In Python)
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
Write by hand a full java program that will prompt the user for the length and...
Write by hand a full java program that will prompt the user for the length and width of a square, calculate and display the area of that square rounded to the nearest tenth with an appropriate message.
Write a java program. The program requirements are: the program will let the user input a...
Write a java program. The program requirements are: the program will let the user input a starting number, such as 2.  It will generate ten multiplication problems ranging from 2x1 to 2x10.  For each problem, the user will be prompted to enter the correct answer. The program should check the answer and should not let the user advance to the next question until the correct answer is given to the question being asked currently. After testing a total of 10 multiplication problems,...
Write a program that will input the information for 2 different employees. Prompt the user for...
Write a program that will input the information for 2 different employees. Prompt the user for the first employee’s name, hours worked and rate. Compute the salary and display it. Do the same for the second and third employees. Then, display a message to the effect that the highest salary is whatever and the lowest salary is whatever. When the program runs, the following should display information should line up just as I have it below. E:\> java Quiz4 Name:...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT