春夏秋冬四季
Scanner sn =new Scanner(System.in);
System.out.println("请输入月份:");
int month = sn.nextInt();
/*
switch (month){
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;
case 10:
System.out.println("秋季");
break;
case 11:
System.out.println("秋季");
break;
case 12:
System.out.println("冬季");
break;
default:
System.out.println("enheng");
}
*/
//case 穿透 优化上面程序
switch (month) {
case 1:
case 2:
case 12:
System.out.println("冬季");
break;
case 3:
case 4:
case 5:
System.out.println("春季");
break;
case 6:
case 7:
case 8:
System.out.println("夏季");
break;
case 9:
case 10:
case 11:
System.out.println("秋季");
break;
default:
System.out.println("再来一遍");
}
for 循环结构
1-5求和
for (int i=1;i<=5;i++){
System.out.println("第"+i+"次,输出");
}
for (int j=5;j>=1;j--){
System.out.println("还有"+j+"次,输出");
}
1-100偶数求和
int sum =0;
for (int i=0;i<=100;i++){
if (i%2==0){
sum += i;
}
}
System.out.println("1-5的和是:"+sum);
水仙花
商(除)+取余 =数字
//遍历所有三位数
for (int i=100;i<=999;i++){
//获取三位数中每个单位上的值
int ge = i%10;
int shi = i/10%10;
int bai = i/10/10%10;
//判断条件
if (ge*ge*ge+shi*shi*shi+bai*bai*bai==i){
System.out.println(i);
}
}
水仙花数
for (int i=100;i<=999;i++){
//获取三位数中每个单位上的值
int ge = i%10;
int shi = i/10%10;
int bai = i/10/10%10;
//判断条件
if (ge*ge*ge+shi*shi*shi+bai*bai*bai==i){
count++;
}
}
System.out.println("水仙花共有:"+count+"朵");
while循环