我的程序是这样的:public class sa { /**
 * @param args
 */
public static void main(String[] args) {
// TODO Auto-generated method stub
final int STARTRATE=10;
final int NRATES=6;
final int NYEARS=10;

double[] interestRate=new double[NRATES];
for(int j=0;j<interestRate.length;j++)
interestRate[j]=(STARTRATE+j)/100.0;

double[][]balances=new double[NYEARS][NRATES];

for(int j=0;j<balances[0].length;j++)
balances[0][j]=10000;

for(int i=1;i<balances.length;i++)
{
for(int j=0;j<balances[i].length;)
{
double oldBalance=balances[i-1][j];
double interest=oldBalance*interestRate[j];
balances[i][j]=oldBalance+interest;
}
}
for(int j=0;j<interestRate.length;j++)
System.out.printf("%9.0f%%",100*interestRate[j]);

System.out.println();

for(double []row:balances)
{
for(double b:row)
System.out.printf("%10.2f",b);

System.out.println();
}

}}
预期结果是输出一个表格,看了半天觉得程序没什么问题,但是编译到最后什么结果都没有,请大家帮我看一下,先在这里说一声谢谢了!

解决方案 »

  1.   

    楼主请问System.out.printf("%10.2f",b);的printf是什么啊?你编译的通吗?
      

  2.   

    for(int j=0;j<balances[i].length;)
    改成for(int j=0;j<balances[i].length;j++)
    你没有j++.运行程序已经死循环了..
      

  3.   


    PrintStream java.io.PrintStream.printf(String format, Object... args)
    A convenience method to write a formatted string to this output stream using the specified format string and arguments. An invocation of this method of the form out.printf(format, args) behaves in exactly the same way as the invocation      out.format(format, args) 
    Parameters:
    format A format string as described in Format string syntax
    args Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The number of arguments is variable and may be zero. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by the Java Virtual Machine Specification. The behaviour on a null argument depends on the conversion.
    Returns:
    This output stream
    Throws:
    IllegalFormatException If a format string contains an illegal syntax, a format specifier that is incompatible with the given arguments, insufficient arguments given the format string, or other illegal conditions. For specification of all possible formatting errors, see the Details section of the formatter class specification.
    NullPointerException If the format is null
    Since:
    1.5
    我下载的中文api文档里面怎么找不到printf和print这两个method?
      

  4.   

    printf 和print这两个method都是输出以后不换行。
      

  5.   

    谢谢weihongyong2006()了,你好细心哦,就是这个问题了!
      

  6.   

    回复人:plpblue(水晶) ( 一级(初级)) 信誉:100  2006-7-16 23:23:08  得分:0
    ?  楼主请问System.out.printf("%10.2f",b);的printf是什么啊?你编译的通吗?-----------------------------------------------------------------------------------
    关于找不到print()和printf()的问题我写了篇随笔.在我blog上,自己看了.http://www.blogjava.net/ky1in/archive/2006/07/19/59089.html
      

  7.   

    for(int j=0;j<balances[i].length;)
    汗,这个也掉