Wednesday, August 30, 2017

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

This example is for Java beginners to let them learn two basic concepts of the language
1. for loop
2. Using Scanner class to get input from keyboard

import java.util.Scanner;

public class TableOfInteger {

     // start of main() function

        public static void main(String[] args) {

        Scanner keyboard = new Scanner(;

        // 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