import java.text.NumberFormat;
import javax.swing.*;
import java.util.Locale;
public class P15759
{
public static void main( String arg[] )
{
double amount;
double principal = 1000.0;

NumberFormat moneyFormat = 
NumberFormat.getCurrencyInstance( Locale.US ); JTextArea outputTextArea = new JTextArea(17,20);
JScrollPane scroller = new JScrollPane( outputTextArea );
outputTextArea.setText( "Year\tAmount on deposit\n" ); for (double rate = 0.05; rate <= 0.1; rate += 0.01)
{
for ( int year = 1; year <= 10 ; year++ )
{
amount = principal * Math.pow( 1.0 + rate, year ); outputTextArea.append( year + "\t" +
moneyFormat.format( amount ) + "\n"  );
}
} JOptionPane.showMessageDialog( null,scroller,
"Compound Interset", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 );
}
}现在弄好了滚动条后..如何添加每循环10次的自动后中间空一行在添加循环计算结果呢?

解决方案 »

  1.   


    for ( int year = 1; year <= 10 ; year++ ) 

    amount = principal * Math.pow( 1.0 + rate, year ); outputTextArea.append( year + "\t" + 
    moneyFormat.format( amount ) + "\n"  ); 

    outputTextArea.append("\r\n");直接加一条
      

  2.   

    下次贴代码规范点好吗,看起脑壳疼。
    import java.text.NumberFormat; 
    import javax.swing.*; 
    import java.util.Locale; 
    public class P15759 

    public static void main( String arg[] ) 

    double amount; 
    double principal = 1000.0; NumberFormat moneyFormat = 
    NumberFormat.getCurrencyInstance( Locale.US ); JTextArea outputTextArea = new JTextArea(17,20); 
    JScrollPane scroller = new JScrollPane( outputTextArea ); 
    outputTextArea.setText( "Year\tAmount on deposit\n" ); for (double rate = 0.05; rate <= 0.1; rate += 0.01) 

    for ( int year = 1; year <= 10 ; year++ ) 

    amount = principal * Math.pow( 1.0 + rate, year ); outputTextArea.append( year + "\t" + 
    moneyFormat.format( amount ) + "\n"  ); 
    } //这个地方加代码就行了。
    //为了演示。加了一个换行。你可以先运行看效果。
    outputTextArea.append( "\n" );
    } JOptionPane.showMessageDialog( null,scroller, 
    "Compound Interset", JOptionPane.INFORMATION_MESSAGE ); System.exit( 0 ); 

    }