-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadUserInput.java
More file actions
31 lines (22 loc) · 817 Bytes
/
Copy pathReadUserInput.java
File metadata and controls
31 lines (22 loc) · 817 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
28
29
30
31
import java.util.Scanner;
public class ReadUserInput {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("What is your birth year?");
boolean hasNextInt = scanner.hasNextInt();
if(hasNextInt){
int age = 2022 - scanner.nextInt();
if(age > 0 && age <=100){
scanner.nextLine();
System.out.println("What is your name?");
String name = scanner.nextLine();
System.out.println("Hi my name is " + name + " my age is " + age );
}else{
System.out.println("Invaild age");
}
}else{
System.out.println("Invaild data type");
}
scanner.close();
}
}