好吧,我已经为印度货币卢比建立了一个面额计数器。说,如果你输入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