-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSolution.java
More file actions
63 lines (51 loc) · 1.94 KB
/
Copy pathSolution.java
File metadata and controls
63 lines (51 loc) · 1.94 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package java_datatypes;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
public class Solution {
public static void main(String[] args) throws FileNotFoundException {
Scanner in = new Scanner(new FileReader("./data/java_datatypes/input"));
int t = in.nextInt();
List<DataType> dataTypes = new ArrayList<>(
List.of(new DataType("byte", Byte.MIN_VALUE, Byte.MAX_VALUE),
new DataType("short", Short.MIN_VALUE, Short.MAX_VALUE),
new DataType("int", Integer.MIN_VALUE, Integer.MAX_VALUE),
new DataType("long", Long.MIN_VALUE, Long.MAX_VALUE)));
for(int i = 0; i < t; i++) {
try {
long x = in.nextLong();
//This is not my writing, this is required for sample
System.out.println(x + " can be fitted in:");
//Output the correct data that the sample wants
dataTypes.stream()
.filter(dataType -> x >= dataType.getMinValue() && x <= dataType.getMaxValue())
.forEach(dataType -> System.out.printf("* %s%n", dataType.getName()));
} catch(Exception e) {
//This is not my writing, this is required for sample
System.out.println(in.next()+" can't be fitted anywhere.");
}
}
in.close();
}
}
class DataType {
private final String name;
private final long minValue;
private final long maxValue;
public DataType(String name, long minValue, long maxValue) {
this.name = name;
this.minValue = minValue;
this.maxValue = maxValue;
}
public String getName() {
return name;
}
public long getMinValue() {
return minValue;
}
public long getMaxValue() {
return maxValue;
}
}