public class Text2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请输入月份");
int month = input.nextInt();
String wordOfMonth;
switch (month) {
case 1:
wordOfMonth = "January";
break;
case 2:
wordOfMonth = "February";
break;
case 3:
wordOfMonth = "Marh";
break;
case 4:
wordOfMonth = "April";
break;
case 5:
wordOfMonth = "May";
break;
case 6:
wordOfMonth = "june";
break;
case 7:
wordOfMonth = "july";
break;
case 8:
wordOfMonth = "August";
break;
case 9:
wordOfMonth = "September";
break;
case 10:
wordOfMonth = "October";
break;
case 11:
wordOfMonth = "November";
break;
case 12:
wordOfMonth = "Decenmber";
break;
default:
wordOfMonth = "输入错误";
break;
}
System.out.println(wordOfMonth);
input.close();
}
}
二 循环结构案例
1:while循环举例
对于 while 语句而言,如果不满足条件,则不能进入循环。
public class Text5 {
public static void main(String[] args) {
int i=0;
while (i<10) {
System.out.println("Hello,word!"); i+=1;
}
System.out.println("结束");
int sum = 0;
int i = 0;
while(i<=100){ if(i%3==0||i%5==0||i%7==0) { sum+=i; }
i+=1; } System.out.println(sum);
do {
sum += i;
i += 1;
} while (i <= 100);
System.out.println(sum);