Wednesday, August 30, 2017

Java example for generating a table of a number and for loop

/* this example explains two important topics of Java
1. for loop
2. generate the table of any number got from keyboard
*/
 
import java.util.Scanner;

public class TableOfInteger {
     // start of main() function
        public static void main(String[] args) {

        Scanner keyboard = new Scanner(System.in);
        // get an object of Scanner class for getting input from keyboard
        System.out.println("enter an integer for generate table ");
        int table = keyboard.nextInt();
        // for loop
        for(int i=1;i<=10;i++)
                                System.out.println(table + "X" + i +"=" +table*i);
       
                        
}
//end of main function()

}

No comments:

Post a Comment