Java program to Accept Input from User Using Scanner Class

In java, there are different ways to accept input from user, we can also accept input from user in java using scanner class. scanner class is a predefined class in java.util package, and we can type cast  input in different data type.

// Java program to accept input from user using Scanner class.

import java.util.Scanner;
 
class GetInput
{
    public static void main(String args[])
    {
        Scanner in = new Scanner(System.in);
	int a,b,c; 
        a = in.nextInt();
        b = in.nextInt();
	c=a+b;
        System.out.println("SUM : "+c);
 
    }
}
Share with your Friends...
One comment

It is hard to come by experienced people about this subject, but you seem like you know what you are talking about! Thanks

Leave a Comment

Your email address will not be published. Required fields are marked *

The NuCaptcha API requires the PHP mcrypt module.