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);
 
    }
}

Leave a Comment

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

Scroll to Top