基础练习 报时助手 Java
代码:
import java.util.*;
public class 报时助手 {
public static void main(String[] args) {
String a[] = {"zero","one","two","three","four",
"five","six","seven","eight","nine",
"ten","eleven","twelve","thirteen",
"fourteen","fifteen","sixteen",
"seventeen","eighteen","nineteen","twenty"};
int h,m;
Scanner sc = new Scanner(System.in);
h = sc.nextInt();
m = sc.nextInt();
if(h <= 20){
System.out.print(a[h] + " ");
}else{
int x = h - 20;
//System.out.println(x);
System.out.print("twenty" + " " + a[x] + " ");
}
if(m == 0){
System.out.print("o'clock");
}else{
if(m <= 20){
System.out.print(a[m]);
}else if(m > 20 && m < 30){
int x = m - 20;
System.out. print(a[20] + " " + a[x]);
}else if(m >= 30 && m < 40){
int x = m - 30;
if(x == 0){
System.out.print("thirty");
}else{
System.out.print("thirty" + " " + a[x]);
}
}else if(m >= 40 && m < 50){
int x = m - 40;
if(x == 0){
System.out.print("forty");
}else{
System.out.print("forty" + " " + a[x]);
}
}else if(m >= 50 && m < 60){
int x = m - 50;
if(x == 0){
System.out.print("fifty");
}else{
System.out.print("fifty" + " " + a[x]);
}
}
}
}
}