One of the strengths of Java is the huge libraries of code available to you. This is code that has been written to do specific jobs. All you need to do is to reference which library you want to use, and then call a method into action. One really useful class that handles input from a user is called the Scannerclass. The Scanner class can be found in the java.util library. To use the Scanner class, you need to reference it in your code. This is done with the keyword import.
import java.util.Scanner;
The import statement needs to go just above the Class statement:
import java.util.Scanner;
Scanner class are used in the program below :-
1) nextInt to input an integer
2) nextFloat to input a float
3) nextLine to input a string
1) nextInt to input an integer
2) nextFloat to input a float
3) nextLine to input a string
Scanner in=new Scanner(System.in);
int a,b,sum;
System.out.print("Enter Number1 : ");
a=in.nextInt();
System.out.print("Enter Number 2 : ");
b=in.nextInt();
sum=a+b;
String strl=Integer.toString(sum);
System.out.println("Sum= "+ strl);