Skip to main content

User input java program for java beginners

No replies
arnavkumartechno
Offline
Joined: 2013-10-25
Points: 0

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Scanner_Demo
{
public static void main(String[] args) throws IOException
{
Scanner scanner =new Scanner(System.in);
System.out.print("Enter the name = ");
String name=scanner.nextLine();
System.out.print("Enter the first number = ");
int a=scanner.nextInt();
System.out.print("Enter the second number = ");
int b=scanner.nextInt();
System.out.println("Name is = "+name);
System.out.println("Addition of "+a+" and "+b+" = "+(a+b));
}
}

OUTPUT:
Enter the name = Techknow
Enter the first number = 20
Enter the second number = 50
Name is = Techknow
Addition of 20 and 50 = 70