Sunday, April 3, 2016

Print out table of any number given by the user

As we have already studied about "For Loop" , now we will see some example codes for that.
if you haven't read that before then check out : Introduction to loop and its types .
For example if you want to print out table of any number , given by the user then you can use "For" loop for that process and the code will become:


package table;
import java.util.Scanner;

public class Table
{
    public static void main(String[] args)
    {
        Scanner input=new Scanner(System.in);
        System.out.print("Enter an integer: ");
        int a=input.nextInt();
        for(int i=1;i<=10;i++)
        {
            int b=a*i;
            System.out.println(a+" * "+i+"= "+b);
        }
        
    }
}



0 comments:

Post a Comment