解题思路:把m分成两种情况的数据:第一种m>=0&&m<=20把该块数字的英文用一个字符串数组存储;第二种m>20&&m<60使用switch(m/10)判断十位,再用strs[m%10]输出各位
把h分为:1.m为0的情况,后面加o'clock;2.m不为0的情况,后面跟分钟。两种情况都有h>=0&&h<=20的情况和h>20&&h<=24两种情况
注意事项:
参考代码:package Lanqiao;
import java.util.Scanner;
public class Demo31
{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int h=sc.nextInt();
int m=sc.nextInt();
String[] strs={"zero","one","two","three","four","five",
"six","seven","eight","nine","ten","eleven","twelve",
"thirteen","fourteen","fifteen","sixteen","seventeen",
"eighteen","nineteen","twenty"};
if(m==0)
{
if(h>=0&&h<=20)
{
System.out.println(strs[h]+" o'clock");
}
else
{
System.out.println("twenty"+" "+strs[h%10]+"o'clock");
}
}
else
{
if(h>=0&&h<=20)
System.out.print(strs[h]+" ");
else
{
System.out.print("twenty"+" "+strs[h%10]+" ");
}
if(m>=0&&m<=20)
{
System.out.println(strs[m]);
}
else
{
switch(m/10)
{
case 2:
System.out.println("twenty"+" "+strs[m%10]);
break;
case 3:
System.out.println("thirty"+" "+strs[m%10]);
break;
case 4:
System.out.println("forty"+" "+strs[m%10]);
break;
case 5:
System.out.println("fifty"+" "+strs[m%10]);
break;
}
}
}
}
}
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题10.1 (C语言代码)浏览:1516 |
C语言程序设计教程(第三版)课后习题5.6 (C语言代码)浏览:563 |
用筛法求之N内的素数。 (C语言代码)浏览:1385 |
【蟠桃记】 (C语言代码)浏览:697 |
Wu-求圆的面积 (C++代码)浏览:1994 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:760 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:561 |
C二级辅导-计负均正 (C语言代码)浏览:523 |
Pascal三角 (C语言代码)浏览:707 |
计算质因子 (C语言代码)浏览:778 |