设有3个数组内容如下:String x[]={"zero","one","two","three",four","five","six",seven","eight","ni设有3个数组内容如下:String x[]={"zero","one","two","three",four","five","six",seven","eight","nine"} ; String y[]={ten","eleven","twelve
来源:学生作业帮助网 编辑:作业帮 时间:2024/09/01 16:22:01
设有3个数组内容如下:String x[]={"zero","one","two","three",four","five","six",seven","eight","ni设有3个数组内容如下:String x[]={"zero","one","two","three",four","five","six",seven","eight","nine"} ; String y[]={ten","eleven","twelve
设有3个数组内容如下:String x[]={"zero","one","two","three",four","five","six",seven","eight","ni
设有3个数组内容如下:
String x[]={"zero","one","two","three",four","five","six",seven","eight","nine"} ;
String y[]={ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen" };
String z[]={"twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety" };
用Java命令行输入一个小于100的整数,将其翻成英文表示.
例如:
输入32,输出:thirty two
输入14,输出:fourteen
输入8,输出:eight
反之,输入英文表示,输出相应的整数.
public class test1 {
public static void main(String []args){
System.out.println(CtoE (32));
System.out.println(CtoE (14));
System.out.println(CtoE (8));
}
public static String CtoE(int a){
String x[]={"zero","one","two","three","four","five","six","seven","eight","nine"} ;
String y[]={"ten","eleven","twelve","thirteen","fourteen","fifteen","sixteen","seventeen","eighteen","nineteen" };
String z[]={"twenty","thirty","fourty","fifty","sixty","seventy","eighty","ninety" };
if(a>=0&a=10&a=20&a
设有3个数组内容如下:String x[]={"zero","one","two","three",four","five","six",seven","eight","ni设有3个数组内容如下:String x[]={"zero","one","two","three",four","five","six",seven","eight","nine"} ; String y[]={ten","eleven","twelve
public static void main(String[] args) {
System.out.println(CtoE("twenty two"));
System.out.println(CtoE("ten"));
System.out.println(CtoE("five"));
}
public static String CtoE(String a) {
String shiwei = "";
String gewei = "";
String intShiWei = "";
String intGeWei = "";
a=a.toLowerCase();//全都转换成小写字母
//a.trim()去掉字母前后空格
if(a.trim().indexOf(" ")>-1)
{
shiwei = a.substring(0,a.indexOf(" "));
gewei = a.substring(a.lastIndexOf(" "),a.length());
//十位
if("twenty".equals(shiwei.trim())){
intShiWei ="2";
}else if("thirty".equals(shiwei.trim())){
intShiWei ="3";
}else if("fourty".equals(shiwei.trim())){
intShiWei ="4";
}else if("fifty".equals(shiwei.trim())){
intShiWei ="5";
}else if("sixty".equals(shiwei.trim())){
intShiWei ="6";
}else if("seventy".equals(shiwei.trim())){
intShiWei ="7";
}else if("eighty".equals(shiwei.trim())){
intShiWei ="8";
}else if("ninety".equals(shiwei.trim())){
intShiWei ="9";
}
//个位
if("zero".equals(gewei.trim())){
intGeWei ="0";
}else if("one".equals(gewei.trim())){
intGeWei ="1";
}else if("two".equals(gewei.trim())){
intGeWei ="2";
}else if("three".equals(gewei.trim())){
intGeWei ="3";
}else if("four".equals(gewei.trim())){
intGeWei ="4";
}else if("five".equals(gewei.trim())){
intGeWei ="5";
}else if("six".equals(gewei.trim())){
intGeWei ="6";
}else if("seven".equals(gewei.trim())){
intGeWei ="7";
}else if("eight".equals(gewei.trim())){
intGeWei ="8";
}else if("nine".equals(gewei.trim())){
intGeWei ="9";
}
}else
{
if("zero".equals(a.trim())){
intGeWei ="0";
}else if("one".equals(a.trim())){
intGeWei ="1";
}else if("two".equals(a.trim())){
intGeWei ="2";
}else if("three".equals(a.trim())){
intGeWei ="3";
}else if("four".equals(a.trim())){
intGeWei ="4";
}else if("five".equals(a.trim())){
intGeWei ="5";
}else if("six".equals(a.trim())){
intGeWei ="6";
}else if("seven".equals(a.trim())){
intGeWei ="7";
}else if("eight".equals(a.trim())){
intGeWei ="8";
}else if("nine".equals(a.trim())){
intGeWei ="9";
}else if("ten".equals(a.trim())){
intGeWei ="10";
}else if("eleven".equals(a.trim())){
intGeWei ="11";
}else if("twelve".equals(a.trim())){
intGeWei ="12";
}else if("thirteen".equals(a.trim())){
intGeWei ="13";
}else if("fourteen".equals(a.trim())){
intGeWei ="14";
}else if("fifteen".equals(a.trim())){
intGeWei ="15";
}else if("sixteen".equals(a.trim())){
intGeWei ="16";
}else if("seventeen".equals(a.trim())){
intGeWei ="17";
}else if("eighteen".equals(a.trim())){
intGeWei ="18";
}else if("nineteen".equals(a.trim())){
intGeWei ="19";
}
}
return (intShiWei+intGeWei);
}
这是最笨的方法了,其他的我还不知道,这个方法就是数越大,if越多,可以实现大于100的数,如果你常用的话,可以把这个写成一个通用的工具类