import java.util.Scanner;
public class Test01 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("請(qǐng)輸入年份: ");
System.out.println("請(qǐng)輸入月份");
int year = input.nextInt();
int month = input.nextInt();
if (year > 0 && month > 0 && month <= 12){
int day;
if (month == 2){
if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0){
day = 29;
}
else{
day = 28;
}
}
else if (month == 4 | month == 6 | month == 9 | month == 11){
day = 30;
}
else{
day = 31;
}
System.out.println(year + "年" + month + "月" + "有" + day + "天");
}
else {
System.err.println("輸入錯(cuò)誤");
}
input.close();
}
}
switch(){ // 整數(shù)弦牡,字符胎许,枚舉该押,字符串
}
case 1:
break;
case 2:
break;
default:
break;
import java.util.Scanner;
public class Test02 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("請(qǐng)輸入月份: ");
int month = input.nextInt();
String wordOfMonth;
switch (month) {
case 1:
wordOfMonth = "January";
break;
case 2:
wordOfMonth = "February";
break;
case 3:
wordOfMonth = "March";
break;
case 4:
wordOfMonth = "April";
break;
case 5:
wordOfMonth = "May";
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 = "December";
break;
default:
wordOfMonth = "輸入錯(cuò)誤";
break;
}
System.out.println(wordOfMonth);
input.close();
}
}
循環(huán)語句
while(){
}
public class Test05 {
public static void main(String[] args) {
int i = 1;
while(i <= 10){
System.out.println(i + ". Hello,world!");
i += 1;
}
System.out.println("循環(huán)結(jié)束");
}
}
do{
} while();
public class Test07 {
public static void main(String[] args) {
int i = 0;
int sum = 0;
do {
i += 1;
sum += i;
} while (i < 100);
System.out.println(sum);
System.out.println("循環(huán)結(jié)束");
}
}