To change this license header choose License Headers in Project Proper

 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
64
65
66
67
68
69
70
71
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package exa;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author Tanya
*/
public class Main {
/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
List<String> list = new ArrayList<String>();
while (true) {
String str = reader.readLine();
if (str.equals("exit")) {
break;
}else{
list.add(str);
}
}
for (String s : list) {
try {
if (s.contains(".")) {
Double d = new Double(s);
print(d);
} else if (0 < (Integer.parseInt(s)) && (Integer.parseInt(s)) < 128) {
print((short) (Integer.parseInt(s)));
} else if ((Integer.parseInt(s)) >= 128) {
print(Integer.parseInt(s));
} else {
print(s);
}
} catch (NumberFormatException e) {
print(s);
}
}
}
public static void print(Integer value) {
System.out.println("Это тип Integer, значение " + value);
}
public static void print(String value) {
System.out.println("Это тип String, значение " + value);
}
public static void print(short value) {
System.out.println("Это тип short, значение " + value);
}
public static void print(double value) {
System.out.println("Это тип Double, значение " + value);
}
}