我是菜鸟呜呜


私信TA

用户名:dotcpp0769178

访问量:77

签 名:

等  级
排  名 3507
经  验 1879
参赛次数 2
文章发表 39
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

参考代码:

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		//输入时间的时和分
		int h = scanner.nextInt();
		int m = scanner.nextInt();
		
		//新建数组存储数据
		String[] arr= {"zero","one","two","three","four","five",
				"six","seven","eight","nine","ten",   
				"eleven","twelve","thirteen","fourteen","fifteen",
				"sixteen","seventeen","eighteen","nineteen","twenty",
				"thirty","forty","fifty"};
		//先读取h
		if (h <= 20) {
			System.out.print(arr[h] + " ");
		}else {
			//如果大于20小于60的
			//先读取整十的数,然后再加上个位数
			System.out.print(arr[h - h % 10] + " " + arr[h % 10] + " ");
		}
		//再读取m
		if (m == 0) {
			System.out.println("o'clock");
		}else {
			if (m <= 20) {
				System.out.println(arr[m] + " ");
			}else {
				//大于20小于60的
				//30 40 50 在数组中的索引是21 22 23
				int x = m / 10 - 2;//获取30,40 50中的3 4 5 - 2 = 1 2 3
				System.out.println(arr[20 + x] + " " + arr[m % 10]);
			}
		}
	}
}


 

0.0分

1 人评分

  评论区

  • «
  • »