In: Computer Science
Write a Java program named, MultiTable, (MultiTable.java), with the following tasks:
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
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
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); } }
===================================================================