Write a program to print reverse tables


This Java program is similar to the previous program, but it prints the multiplication table of the specified number in reverse order, from the ending number to the starting number.

Here's a step-by-step breakdown of how the program works:

  • The program starts by importing the java.util.Scanner class, which is used to read user input from the console.
  • The Reverse_Tables class is defined and the main method is declared.
  • Inside the main method, an instance of the Scanner class is created and assigned to a variable named input.
  • The program prompts the user to input the starting number by printing the message "Enter The Starting Number : " to the console. The nextInt() method of the Scanner class is then used to read an integer value from the console and assign it to a variable named s.
  • The program prompts the user to input the ending number by printing the message "Enter The Ending Number : " to the console. The nextInt() method of the Scanner class is then used to read an integer value from the console and assign it to a variable named e.
  • The program prompts the user to input the tables number by printing the message "Enter The Tables Number : " to the console. The nextInt() method of the Scanner class is then used to read an integer value from the console and assign it to a variable named t.
  • The program enters a while loop that will execute as long as the value of s is greater than or equal to the value of e.
  • Inside the while loop, the program prints the current value of s, the tables number t, and the product of s and t to the console using the println() method of the System.out object.
  • The value of s is then decremented by 1 using the -- operator.
  • The program returns to the beginning of the while loop and checks the condition again. If the value of s is still greater than or equal to the value of e, the loop will continue to execute. If not, the loop will terminate and the program will exit.

Source Code

import java.util.Scanner;
class Reverse_Tables
{
	public static void main(String[] args)
	{
		Scanner input = new Scanner(System.in);
		System.out.print("Enter The Starting Number : ");
		int s =input.nextInt();
		System.out.print("Enter The Ending Number : ");
		int e =input.nextInt();
		System.out.print("Enter The Tables Number : ");
		int t =input.nextInt(); 
		while(s>=e)
		{
			System.out.println(s+" * "+t+" = "+(s*t));
			s--;
		}
	}
}

Output

Enter The Starting Number : 10
Enter The Ending Number : 1
Enter The Tables Number : 5
10 * 5 = 50
9 * 5 = 45
8 * 5 = 40
7 * 5 = 35
6 * 5 = 30
5 * 5 = 25
4 * 5 = 20
3 * 5 = 15
2 * 5 = 10
1 * 5 = 5

Example Programs