原文是java的内容,正好用在了Swift上,Good Job!

原文地址:立即访问

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
import java.io.*;

public class tryCase1 {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

int age;


BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
try {
age = Integer.parseInt(br.readLine());

switch (age>0?(age>17?(age>29?(age>59?4:3):2):1):-1){
case (1):
System.out.println("少年");
break;
case (2):
System.out.println("青年");
break;
case (3):
System.out.println("中年");
break;
case (4):
System.out.println("老年");
break;
case (-1):
System.out.println("你输入的数值不合法");
break;

default:
System.out.println("default");
break;

}
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}


}

}