導航:首頁 > 編程語言 > java分轉換為元

java分轉換為元

發布時間:2023-03-22 22:01:55

『壹』 一演算法題java實現,有一分錢,兩分錢,五分錢,加起來等於10元錢。有多少種方法,並列印出來高手指教

一共50401組數據

public class ABC {
public static void main(String args[]) {

final int total = 1000;/穗渣/一共1000分

int count = 0;
for(int one = 0; one <= total / 1; one++){//察好1分錢數目
for(int two = 0; two <= total / 2; two++){//2分錢數目
for(int five = 0; five <= total / 5; five++){//5分錢數目
if(one*1 + two*2 + five *5 == total){
System.out.println("1*" + one + "敗族鉛 + 2*" + two + " + 5*" + five + "= 1000" );
count++;
}
}
}
}

System.out.println("Total possible " + count + " group!");
}
}
------------------
。。。。。
1*996 + 2*2 + 5*0= 1000
1*998 + 2*1 + 5*0= 1000
1*1000 + 2*0 + 5*0= 1000
Total possible 50401 group!

『貳』 Java定義一個表示人民幣的類Money,

public class Money {
private int yuan;
private int jiao;
private int fen;

public Money(int yuan,int jiao, int fen){
this.yuan=yuan;
this.jiao=jiao;
this.fen=fen;

}

public void show(){

System.out.printf("%d元回%d角%d分",yuan,jiao,fen);

}

public static void main(String[] args) {
答Money m=new Money(4,5,6);
m.show();

}

}

『叄』 JAVA程序 輸入一串數字如12341289.23,輸出萬千百十元角分。高手幫忙!謝謝

//將人民幣金額轉換為大寫
function upDigit(n){
var fraction = ["角","分"];
var digit = ["零","壹","貳","叄","肆","伍","陸","柒","捌","玖"];
var unit = [["元","萬","億"],["","拾","佰","仟"]];
var head = n<0?"負":"";
n = Math.abs(n);

var s = "";
for(var i=0; i<fraction.length; i++){
s += (digit[Math.floor(n*10*Math.pow(10,i))%10]+fraction[i]).replace(/零./,"");
}

s = s||"整";
n = Math.floor(n);

for(var i=0; i<unit[0].length && n>0; i++){
var p = "";
for(var j=0; j<unit[1].length && n>0; j++){
p = digit[n%10] + unit[1][j]+p;
n = Math.floor(n/10);
}
s = p.replace(/(零.)*零$/,"").replace(/^$/,"零") + unit[0][i] + s;
}
return head + s.replace(/(零.)*零元/,"元").replace(/(零.)+/g,"零").replace(/(^整$)/,"零元整");
}

閱讀全文

與java分轉換為元相關的資料

熱點內容
如何從數控編程小白到大師 瀏覽:183
更改微信共享實時位置信息 瀏覽:13
js姓名正則 瀏覽:843
如何利用串口傳輸文件夾 瀏覽:346
jca文件怎麼用word打開 瀏覽:965
U盤文件木馬隱藏exe工具 瀏覽:152
下載優酷app視頻播放器安裝 瀏覽:38
兩個excel文件不同 瀏覽:585
如何更新網站內容 瀏覽:953
什麼網站下載廣場舞是免費的 瀏覽:307
西門子編程軟體怎麼變成中文 瀏覽:984
居客來wifi密碼 瀏覽:604
文件為何為空linux 瀏覽:630
美劇鳥app安裝包在手機哪裡 瀏覽:985
蘋果5s16g升級ios103 瀏覽:850
word紅頭文件中怎麼加雙線 瀏覽:825
切割機用什麼編程 瀏覽:787
文件修訂題目 瀏覽:572
魅族pro5自帶瀏覽器怎麼升級 瀏覽:342
為什麼用數據還是載入慢 瀏覽:171

友情鏈接