-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInput.java
More file actions
27 lines (22 loc) · 799 Bytes
/
UserInput.java
File metadata and controls
27 lines (22 loc) · 799 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import java.util.Scanner;
public class UserInput{
public static void main(String[] args){
// input for text
Scanner scanner = new Scanner(System.in);
System.out.println("Enter your name");
String userName = scanner.nextLine(); //input
System.out.println("Welcome to Java course " + userName);
//Input for Number
System.out.println("Enter your age");
int age = scanner.nextInt();
System.out.println("Your age is : " + age);
//Simple calculation
System.out.println("Please enter a number");
int a = scanner.nextInt();
System.out.println("Please enter a number");
int b = scanner.nextInt();
int sum = a + b;
System.out.println("The sum is :" + sum);
scanner.close();
}
}