2007叶光津


私信TA

用户名:uq_70078723231

访问量:5509

签 名:

工资1800,每日笑哈哈

等  级
排  名 594
经  验 4084
参赛次数 1
文章发表 14
年  龄 0
在职情况 学生
学  校 湖北生物科技职业学院
专  业

  自我简介:

TA的其他文章

解题思路:将特殊的时间都存放在数组中,方便后面直接输出

注意事项:

参考代码:

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		String[] strs = { "zero", "one", "two", "three", "four", "five", "six",
				"seven", "eight", "nine", "ten", "eleven", "twelve",
				"thirteen", "fourteen", "fifteen", "sixteen", "seventeen",
				"eighteen", "nineteen", "twenty", };
		Scanner scanner = new Scanner(System.in);
		int h = Integer.parseInt(scanner.next());
		String sh = "";
		int m = Integer.parseInt(scanner.next());
		String sm = "";
		if (h <= 20) {
			sh = strs[h];
		} else if (h < 30) {
			sh = "twenty " + strs[h - 20];
		} else if (h < 40) {
			if (h == 30)
				sh = "thirty";
			sh = "thirty " + strs[h - 30];
		} else if (h < 50) {
			if (h == 40)
				sh = "forty";
			sh = "forty " + strs[h - 40];
		} else if (h < 60) {
			if (h == 50)
				sh = "fifty";
			sh = "fifty " + strs[h - 50];
		}

		if (m == 0) {
			sm = "o'clock";
		} else if (m <= 20) {
			sm = strs[m];
		} else if (m < 30) {
			sm = "twenty " + strs[m - 20];
		} else if (m < 40) {
			if (m == 30)
				sm = "thirty";
			sm = "thirty " + strs[m - 30];
		} else if (m < 50) {
			if (m == 40)
				sm = "forty";
			sm = "forty " + strs[m - 40];
		} else if (m < 60) {
			if (m == 50)
				sm = "fifty";
			sm = "fifty " + strs[m - 50];
		}
		System.out.println(sh + " " + sm);
	}

}


 

0.0分

2 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答

代码解释器

  评论区