說明:與 d067 一樣的判斷方式,只有輸入為 0 時結束判斷。
Java 版
import java.util.Scanner;
public class D070 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (in.hasNext()) {
String input = in.nextLine();
int a = Integer.parseInt(input);
if(a == 0)
break;
else if(((a % 4) == 0 && (a % 100) != 0) || (a % 400) == 0)
System.out.println("a leap year");
else
System.out.println("a normal year");
}
}
}
Python 版 (2022.07)while True:
try:
a = int(input())
if a == 0:
break
elif ((a % 4 == 0) and (a % 100 != 0)) or (a % 400 == 0):
print('a leap year')
else:
print('a normal year')
except:
break
沒有留言:
張貼留言