基础练习 报时助手
程序员文章站
2022-03-14 09:48:47
...
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String[] clock = {"zero ", "one ", "two ", "three ", "four ", "five ", "six ", "seven ", "eight ",
"nine ", "ten ", "eleven ", "twelve ", "thirteen ", "fourteen ", "fifteen ", "sixteen ", "seventeen ",
"eighteen ", "nineteen ", "twenty ", "thirty ", "forty ", "fifty ", "o'clock "};
int h = scanner.nextInt();
int m = scanner.nextInt();
if(h <= 20) {
System.out.print(clock[h]);
} else {
System.out.print(clock[20] + clock[h%10]);
}
if(m <= 20) {
if(m == 0)
System.out.print(clock[24]);
else {
System.out.print(clock[m]);
}
} else {
System.out.print(clock[m/10+18] + clock[m%10]);
}
}
}