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

熱點內容
頁面自適應屏幕如何調整代碼數據 瀏覽:681
jsjson工具 瀏覽:299
資料庫中如何備份一張表的數據 瀏覽:739
網路設備能用到什麼 瀏覽:64
暴風轉碼如何添加文件夾 瀏覽:515
延安整合網路營銷有哪些 瀏覽:74
查找word打開過的文件在哪裡 瀏覽:137
b樹java代碼 瀏覽:683
電腦文件存儲 瀏覽:657
蘭州中考徵集志願在哪個網站 瀏覽:215
cs文件上傳下載 瀏覽:244
拷貝文件到根目錄下重命名linux 瀏覽:603
api函數的頭文件 瀏覽:249
華為怎麼綁定迷你編程 瀏覽:215
機構怎麼申請少兒編程考級 瀏覽:495
崑山數控編程哪裡好學 瀏覽:459
jspcfor跳出 瀏覽:65
word怎麼插入羅馬數字i 瀏覽:315
哪個網站可以找到法人代表 瀏覽:106
蘋果5s日版a1453支持什麼網路 瀏覽:297

友情鏈接