Question

Create A MultiplicationTable program using nested for loops which will display a multiplication table for the...

Create A MultiplicationTable program using nested for loops which will display a multiplication table for the hexadecimal numbers 1 - F. Nested for Hint: if you use the System.out.printf method with a format specifier "%X" it will display an integer value in hexadecimal format.

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

Solution : To calculate the multiplication of each number from 1 to F , we use two for loops, which are nested.The outer for loop iterates from 1 to F(in decimal 15) and the inner for loop iterates from 1 to A(in decimal 10). The resulting multiplication of each number is printed using System.out.print("%X",argument) which prints the numbers in hexadecimal format.

Code :

public class Main {
    public static void main(String[] args) {
        System.out.println("Multiplication table for hexadecimal numbers");
        for (int i = 1; i <= 15; i++) {  // outer for loop for Hexadecimals 1-F

            System.out.printf("%X", i);
            System.out.print(" : ");

            for (int j = 1; j <= 10; j++) { // inner for loop for multiplication upto 10 or in Hexadecimal A
                System.out.printf(" %X", (i * j));
            }
            System.out.println();
        }
    }
}

Output :

We can change the format of our table :

Code :

public class Main {
    public static void main(String[] args) throws Exception {

        System.out.println("Multiplication table for hexadecimal numbers");

        for (int i = 1; i <= 15; i++) {            //outer for loop for Hexadecimals 1-F
            System.out.printf("Table for %X\n", i);

            for (int j = 1; j <= 10; j++) {           //inner for loop for multiplication upto 10 or A(in hexadecimal)
                System.out.printf("%X", i);
                System.out.print(" * ");
                System.out.printf("%X", j);
                System.out.print(" = ");
                System.out.printf(" %X\n", (i * j));
            }
            System.out.println();
        }
    }
}

Output :

Add a comment
Know the answer?
Add Answer to:
Create A MultiplicationTable program using nested for loops which will display a multiplication table for the...
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
  • 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...

  • Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program...

    Lab 5-2 Nested Loops 2. Summation Of Numbers (using Nested While Loops) Part A: The program will calculate and display the total of all numbers up to a specific number (entered by the user). Only positive numbers are allowed. Part B: User-controlled loop Part A Input Validation loop Part A: Summation loop Examples: When 5 is entered the program will calculate the total as 1+2+...+5 and display 15. When 2 is enterered the program will calculate the total as 1+2...

  • Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the...

    Using Python, Can someone please assist in the following: These are the hints: Summary This week's lab is to create a simple multiplication table using nested loops and if statements. Prompt the user for the size of the multiplication table (from 2x2 to 10x10). Use a validation loop to display a warning if the number is less than 2 or greater than 10 and prompt the user to enter the data again until they enter a valid number Put a...

  • Display for patterns using loops In python language!!!!!!!! including comments!!!! Use nested loops that display the...

    Display for patterns using loops In python language!!!!!!!! including comments!!!! Use nested loops that display the following patterns in four separate programs:

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

  • Please create a PHP program that will incorporate TWO for loops which are nested. This program...

    Please create a PHP program that will incorporate TWO for loops which are nested. This program should populate a "Checker board" using alternating color values are red and black. This checkerboard width -"300px". Each cell height and width should = "35px". Border set to = "1px" cell padding-"1px" and cell spacing "1px

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

  • Python Help Create a program that outputs a table from 1 to 5 using what you've...

    Python Help Create a program that outputs a table from 1 to 5 using what you've learned about "for" loops. Your program will print the number and indicate if the number is odd or even. If it is not odd you will multiply 2 numbers with it: number 1 and number 2. Your program must do the multiplication for only even numbers in the table. The output of your program should look like the figure below. Hint: Create a program...

  • Task 5.2 Numerical Analysis Using Nested Loops (13 pts) Consider the following program: void setup() {...

    Task 5.2 Numerical Analysis Using Nested Loops (13 pts) Consider the following program: void setup() { //Read a positive integer from the user //Your code starts here } Complete this program such that it calculates all prime numbers between 1 and the value that is assigned to variable num and outputs them on the screen. A prime number is a positive integer that has no other factors other than itself and 1. You should use a nested loop, i.e., write...

  • Using java Sample Outputs Write a program which asks the user for an integer and then...

    Using java Sample Outputs Write a program which asks the user for an integer and then prints the following patterns based on that integer. Input Validation For Pattern 1, the input must be a value between 1 and 999 For Pattern 2, the input must be a value between 1 and 26. Requirements: For Pattern 1: must be able to work with up to three digit numbers. You will want to use printf to get the spacing correct. For Pattern...

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