User Input

import java.util.Scanner; 

public class UserInput 

{  

public static void main (String args[]) 

  { 

int num; 

Scanner S1= new Scanner(System.in);   

System.out.println("enter any integer");

num = S1.nextInt();  

System.out.println("you entered" + " " + num);  

  } 

}

import keyword is used to include the package in our program. 

util is a package. 

Scanner here is a function - with the help of function object is created.  

S1- it is an object.

nextInt( ) - this is a function used for integer input.  

java - all packages will be stored under java directory. 

Note:- class name and folder name will be same.

Comments