摘自传智播客公开课
package test;
import java.util.Scanner;
public class Arithmetic3 {
//题设:某门户网站,具有如下业务功能
// 客户输入个人信息时,当输入年龄,会根据输入的年龄值
// 显示其所属年龄段
//问题:上述业务日均访问量超百万次,设计完成上述功能的程序
//百万次访问次数多,要求速度最快,一定是速度优先,时间尽量少
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int num = sc.nextInt();
//方案一
System.out.print("方案一:");
if(0<num&&num<9) {
System.out.println("儿童");
}else if(num<19) {
System.out.println("少年");
}else if(num<29) {
System.out.println("青年");
}else if(num<39) {
System.out.println("青壮年");
}else if(num<49) {
System.out.println("壮年");
}else if(num<59) {
System.out.println("中年");
}else if(num<69) {
System.out.println("中老年");
}else if(num<79) {
System.out.println("老年");
}else if(num<89) {
System.out.println("老老年");
}else if(num<99) {
System.out.println("老老老年 ");
}else {
System.out.println("error!!!");
}
System.out.println("-------------");
//方案二
System.out.print("方案二:");
switch(num/10) {
case 0:
System.out.println("儿童");
break;
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 5:
System.out.println("中年");
break;
case 6:
System.out.println("中老年");
break;
case 7:
System.out.println("老年");
break;
case 8:
System.out.println("老老年");
break;
case 9:
System.out.println("老老老年");
break;
default:
System.out.println("error!!!");
}
System.out.println("-------------");
//方案三
System.out.print("方案三:");
String[] strArry = {"儿童","少年","青年","青壮年","壮年","中年","中老年","老年","老老年","老老老年"};
System.out.println(strArry[num/10]);
}
}