write a program to accept a number from user and print its table by using while loop in Java
Answers
Answered by
9
import java.util.Scanner; //Importing Scanner for input
public class Brainly
{
public static void main(String[] args) //Creating main() function
{
Scanner in = new Scanner(System.in); //Declaring Scanner Object
System.out.print("Enter a number: "); //Asking User to Input an integer
int n = in.nextInt(); //Scanning User Input
System.out.println("\nThe multiplication table is: \n");
int i=1; //Declaring an integer i, and assigning value 1
while(i<=10) //Loop will break when value of i exceeds 10
{
System.out.println(n+"*"+i+" = "+(n*i)); //Printing the value of product of n and i
i++; //Incrementing value of i by 1
}
}
}
public class Brainly
{
public static void main(String[] args) //Creating main() function
{
Scanner in = new Scanner(System.in); //Declaring Scanner Object
System.out.print("Enter a number: "); //Asking User to Input an integer
int n = in.nextInt(); //Scanning User Input
System.out.println("\nThe multiplication table is: \n");
int i=1; //Declaring an integer i, and assigning value 1
while(i<=10) //Loop will break when value of i exceeds 10
{
System.out.println(n+"*"+i+" = "+(n*i)); //Printing the value of product of n and i
i++; //Incrementing value of i by 1
}
}
}
QGP:
You are welcome :)
Similar questions