好吧,我已經爲印度貨幣盧比建立了一個面額計數器。說,如果你輸入Rs。 3453,它給出了這樣的輸出:從結果中消除零(Java)
盧比1000注:3
500個盧比筆記:0
100個盧比筆記:4
盧比50注:1
盧比20個音符:0
10個盧比筆記: 0
5盧比紙幣:0
2枚盧比硬幣:1
1枚盧比硬幣:1
但我想這個輸出和消除所有的零,
盧比1000注:3個
100個盧比筆記:4個
盧比50注:1
2枚盧比硬幣:1個
盧比1枚硬幣:1
這是我的代碼:
import java.io.*;
import javax.swing.JOptionPane;
public class denom {
public static void main(String[] args) throws IOException{
String totalRsString;
int totalRs;
totalRsString = JOptionPane.showInputDialog(null, "Enter amount to be converted", "Denomination Conversion", JOptionPane.INFORMATION_MESSAGE);
totalRs = Integer.parseInt(totalRsString);
//Calculations begin here
int thousand, fh, h, f, twenty, t, fi, tw, o;
thousand = totalRs/1000;
int bal = totalRs - (1000*thousand);
fh = bal/500;
bal = bal - (500*fh);
h = bal/100;
bal = bal - (100 * h);
f = bal/50;
bal = bal - (50*f);
twenty = bal/20;
bal = bal - (20*twenty);
t = bal/10;
bal = bal-(10*t);
fi = bal/5;
bal = bal - (5*fi);
tw = bal/2;
bal = bal - (2*tw);
o = bal/1;
bal = bal - (1*o);
//End of calculation
//Print work.
JOptionPane.showMessageDialog(null, "Total Entered is Rs." + totalRsString + "\n" + "\nThousand rupee notes: " + thousand + "\nFive Hundred Notes: " + fh + "\nHundred notes: " + h + "\nFifty notes: " + f + "\nTwenty notes: " + twenty + "\nTen notes: " + t + "\nFive notes: " + fi +
"\nTwo coins: " + tw + "\nOne coins: " + o);
}
}
謝謝,這個人幫了我很多。你的方法更方便。謝謝Ruakh。 –
@MissionCoding:不客氣! – ruakh