-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataTypeFinder.java
More file actions
41 lines (32 loc) · 1.14 KB
/
Copy pathDataTypeFinder.java
File metadata and controls
41 lines (32 loc) · 1.14 KB
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
32
33
34
35
36
37
38
39
40
41
import java.util.Scanner;
public class DataTypeFinder {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String input = scanner.nextLine();
while(!input.equals("END")){
try{
Integer.parseInt(input);
System.out.printf("%s is integer type%n",input);
input = scanner.nextLine();
continue;
}catch(NumberFormatException e){
}
try{
Double.parseDouble(input);
System.out.printf("%s is floating point type%n",input);
input = scanner.nextLine();
continue;
}
catch(NumberFormatException e){
}
if(input.equalsIgnoreCase("true")|| input.equalsIgnoreCase("false")){
System.out.printf("%s is boolean type%n",input);
}else if(input.length()== 1){
System.out.printf("%s is character type%n",input);
}else {
System.out.printf("%s is string type%n",input);
}
input = scanner.nextLine();
}
}
}