欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

基础练习 报时助手

程序员文章站 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]);
		}
	}
}
相关标签: 蓝桥杯