Its a simple table printing program in java . in this program using Scanner class to get the input from user at runtime.
n is the number which will provided by user.
now for loop will run from 1 to 10 and inside the for loop we are multiplying n with i . i which will run from 1 to 10 and when i<=10 loop will stop .
public class PrintTable
{
public static void main(String[] args)
{
Scanner scn=new Scanner(System.in);
System.out.println(" type a no. to get Table");
int n=scn.nextInt();
for(int i=1;i<=10;i++)
{
System.out.println(n+"*"+i+"="+i*n);
}
}
}
n is the number which will provided by user.
now for loop will run from 1 to 10 and inside the for loop we are multiplying n with i . i which will run from 1 to 10 and when i<=10 loop will stop .
public class PrintTable
{
public static void main(String[] args)
{
Scanner scn=new Scanner(System.in);
System.out.println(" type a no. to get Table");
int n=scn.nextInt();
for(int i=1;i<=10;i++)
{
System.out.println(n+"*"+i+"="+i*n);
}
}
}
Tags:
Basic