Java – Print Multiplication table until user exits

Program to print Multiplication table for given number until user exits:

import java.util.Scanner;
public class Check
{
            public static void main(String[] args)
            {
                        Scanner scan = new Scanner(System.in);
                        while(true)
                        {
                                    System.out.print(“Enter table number : “);
                                    int n = scan.nextInt();
 
                                    for(int i=1 ; i<=10 ; i++)
                                    {
                                                System.out.println(n + ” * ” + i + ” = ” + (n*i));
                                    }
 
                                    System.out.print(“Do you want print another table ? (y/n): “);
                                    char ch = scan.next().charAt(0);
                                    if(ch==’n’)
                                    {
                                                break;
                                    }
                        }
                        System.out.println(“Exiting program.”);
            }
}
Scroll to Top