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

报时助手

程序员文章站 2022-03-14 09:46:41
...

报时助手

import java.util.Scanner;

public class Main{
	private static String [] time1={"zero","one","two","three","four","five","six","seven","eight","nine","ten",
			                        "eleven","twelve","thirteen","fourteen","fifteen","sixteen","eighteen","nineteen"};
	private static String [] time2={"twenty","thirty","forty","fifty"};

	public static void main(String[] args) {
		
		Scanner scan=new Scanner(System.in);
		
		int h=scan.nextInt();
		int m=scan.nextInt();
		
		if(h<20){
			
			System.out.print(time1[h]);
			
		}else if(h==20){
			
			System.out.print(time2[0]);
			
		}else if(h>20&&h<24){
			
			System.out.print(time2[0]+" "+time1[h-20]);
		}
		
		if(m==0){
			
			System.out.print(" "+"o'clock");
			
		}else{
			
			if(m<20){
				
				System.out.print(" "+time1[m]);
				
			}else if(m>=20&&m<60){
				
				int a=m/10;
				int b=m%10;
				
				System.out.print(" "+time2[a-2]+" "+time1[b]);
			}
		}
	}
}


相关标签: string