//这样敲的代码量太大了,求指教简化代码
import java.util.Scanner;
class Random {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入你的名字,我能算出你上辈子的命运");
int result = (int)(Math.random() * 10 - 1);
String name = sc.next();
while(result < 10) {
if (result == 1) {
System.out.println(name+"上辈子是个落单的和尚");
break;
} else if (result == 2) {
System.out.println(name+"上辈子是个小二");
break;
} else if (result == 3) {
System.out.println(name+"上辈子是个宰相");
break;
} else if (result == 4) {
System.out.println(name+"上辈子是个丫鬟");
break;
} else if (result == 5) {
System.out.println(name+"上辈子是八阿哥");
break;
} else if (result == 6) {
System.out.println(name+"上辈子是个家禽");
break;
} else if (result == 7) {
System.out.println(name+"上辈子是个三炮");
break;
} else if (result == 8) {
System.out.println(name+"上辈子是个忍者");
break;
} else if (result == 9) {
System.out.println(name+"上辈子是个贼");
break;
} else {
System.out.println(name+"上辈子是个盗墓者");
break;
}
}
}
}
|
|