0
我正在完成一個學校項目(我的第一個Java課程),我被告知只能使用JOptionPane
。 我需要做這樣的事情但使用JOptionPane
沒有System.out.println
:如何使用內部JOptionPane迭代數組並顯示自定義消息?
int[] den = {1000, 500, 100 ,50, 20, 10 ,5, 2, 1};
System.out.println("\nDENOMINATIONS: \n");
for (int i = 0; i < 9; i++) {
count = amount/den[i]; // counting number of den[i] notes
if (count != 0) { //printing that denomination if the count is not zero
System.out.println(den[i] + "\tx\t" + count + "\t= " + den[i] * count);
}
totalNotes = totalNotes + count; //finding the total number of notes
amount = amount%den[i]; //finding the remaining amount
}
System.out.println("--------------------------------");
System.out.println("TOTAL\t\t\t= " + copy);
System.out.println("--------------------------------");
System.out.println("Total Number of Notes\t= " + totalNotes);
它打印一些美麗的東西是這樣的:
DENOMINATIONS:
1000 x 14 = 14000
500 x 1 = 500
100 x 3 = 300
50 x 1 = 50
5 x 1 = 5
1 x 1 = 1
————————————–
TOTAL = 14856
————————————–
Total Number of Notes = 21
我在想'JTable',但是這樣可以工作;) – MadProgrammer