这道题没什么好讲的,但是需要有几点注意的是,当分钟为0时要输出o’clock,
还有就是数组下标的值和需要的值的对应,下面是代码,仅供参考
import java.util.Scanner; /** * @author 弈鸣coding * @data: 2022/2/5 */ public class Main { public static void main(String[] args) { String[] str = { "zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten","eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen","twenty"}; String[] str1 = { "twenty","thirty","forty","fifty"}; Scanner sc = new Scanner(System.in); int h = sc.nextInt(); int m = sc.nextInt(); int m1 = m/10; int m2 = m%10; String sh = " "; if (h<=20){ System.out.print(str[h]); if (m<=20&&m!=0) { System.out.print(sh+str[m]); }else if (m!=0){ System.out.print(sh+str1[m1-2]+sh+str[m2]); } if (m==0){ System.out.print(sh+"o'clock"); } }else { int hour = h/10; int hour1 = h%10; System.out.print(str1[hour-2]+sh+str[hour1]); if (m<=20&&m!=0) { System.out.print(sh+str[m]); }else if (m!=0){ System.out.print(sh+str1[m1-2]+sh+str[m2]); } if (m==0){ System.out.println(sh+"o'clock"); } } } }