![]() |
PCDVD數位科技討論區
(https://www.pcdvd.com.tw/index.php)
- 七嘴八舌異言堂
(https://www.pcdvd.com.tw/forumdisplay.php?f=12)
- - 可否幫我看看這個JAVA程式....謝謝..!
(https://www.pcdvd.com.tw/showthread.php?t=568715)
|
|---|
可否幫我看看這個JAVA程式....謝謝..!
public class la
{ public static void main(String args[]) { int x = Integer.parseInt(args[0]); String a[]=new String[91]; a[0]="zero"; a[1]="one"; a[2]="two"; a[3]="three"; a[4]="four"; a[5]="five"; a[6]="six"; a[7]="seven"; a[8]="eight"; a[9]="nine"; a[10]="ten"; a[11]="eleven"; a[12]="twelve"; a[13]="thirteen"; a[14]="fourteen"; a[15]="fifteen"; a[16]="sixteen"; a[17]="seventeen"; a[18]="eighteen"; a[19]="nineteen"; a[20]="twenty"; a[30]="thirty"; a[40]="fourty"; a[50]="fifty"; a[60]="sixty"; a[70]="seventy"; a[80]="eighty"; a[90]="ninety"; if (x/1000<=20&&x/1000>0) { System.out.print(a[x/1000] +" thousand "); } else if (x/1000>20) { System.out.print(a[x%1000/100*100]); if(x/1000%10!=0) { System.out.print(" - " + a[x/1000] ); System.out.print(" thousand and "); } else System.out.print(a[x/1000] +" thousand "); } if(x%1000/100==0) { System.out.print(""); } if(x%1000/100!=0) { if(x%100!=0) System.out.print(a[x%1000/100] +" hundred "); else System.out.print(a[x%1000/100] +" hundred and "); } if (x%100<=20&&x%100>0) { System.out.print(a[x%100] +" "); } else if(x%100>20) { System.out.print(a[x%100/10*10]); if(x%10!=0) { System.out.print(" - "+ a[x%10]); } } } } 如上面那個程式..... 我要可以輸入5位數字轉換成英文..... 我打好了.... 但是數入超過20000以上~前面會多出個ZERO..... 然後輸入21~31........後面會出現thousand and可是應該是211~311....才要出現.. 我有設定但是他還是會出現阿.... 然後之後有設定AND都不見了..... 輸入31111..........等等的滿五位數字會錯誤......! 請問一下該如何改呢??? 請各位大大敎我一下吧~~~謝謝....! |
不要用INT接輸入,改用String 接。
|
把INT X改成STRINGX嗎???
這樣就好了嗎?? |
| 所有的時間均為GMT +8。 現在的時間是03:12 PM. |
vBulletin Version 3.0.1
powered_by_vbulletin 2025。