利息的计算(JTextArea和NumberFOrmat的用法) 程序结果: 原文件: // calculate copmound interest import java.text.NumberFormat; import java.util.Locale; import javax.swing.JOptionPane; import javax.swing.JTextArea; public class Interest ... { //main method public static void main(String args[])...{ double amount,principal=100.0,rate=0.05; NumberFormat moneyFormat=NumberFormat.getCurrencyInstance(Locale.US); JTextArea outputTextArea=new JTextArea(); outputTextArea.setText("year Amount on deposit "); for(int year=1;year<=10;year++) ...{ amount=principal*Math.pow(1.0+rate,year); outputTextArea.append(year+" "+moneyFormat.format(amount)+" "); } JOptionPane.showMessageDialog(null,outputTextArea,"Compound interest",JOptionPane.INFORMATION_MESSAGE); System.exit(0); }}