導航:首頁 > 編程語言 > 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分轉換為元相關的資料

熱點內容
cad怎麼統一列印所有文件 瀏覽:958
華為賬號如何擦除數據 瀏覽:927
陽光守護是哪個文件夾 瀏覽:982
js選項卡切換帶左右焦點切換 瀏覽:106
配置文件主要元素 瀏覽:522
tp隱藏wifi密碼 瀏覽:417
js自動刷新 瀏覽:333
電信網路電視4514 瀏覽:278
編程服務軟體是什麼 瀏覽:519
word文件怎麼選擇頁面編輯 瀏覽:645
浩方支持魔獸什麼版本的 瀏覽:553
織夢大型仿站教程 瀏覽:344
怎麼壓縮桌面文件夾 瀏覽:199
數控車床編程到哪裡學 瀏覽:568
一般處理程序session 瀏覽:795
蝙蝠app哪裡加人 瀏覽:974
手游花千骨vip升級 瀏覽:34
ACT文件名 瀏覽:850
無保頑固qq 瀏覽:572
文件如何上傳郵箱 瀏覽:928

友情鏈接