Exercise
Several multiplication tables, (use do while)
Objetive
Write a java program that display multiplication tables from 2 to 6 using nested "do...while" loops.
Example Code
// Importing the Scanner class to handle input from the user
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// Declare variables for multiplication and table number
int number = 2;
// Outer do-while loop to print multiplication tables from 2 to 6
do {
// Print the table number
System.out.println("Multiplication table for " + number);
// Declare the multiplier
int multiplier = 1;
// Inner do-while loop to display the multiplication results for the current table
do {
// Print the result of the multiplication
System.out.println(number + " x " + multiplier + " = " + (number * multiplier));
multiplier++; // Increment the multiplier
} while (multiplier <= 10); // Continue while the multiplier is less than or equal to 10
System.out.println(); // Add a blank line between tables
number++; // Increment the number to print the next table
} while (number <= 6); // Continue until the number reaches 6
}
}