我的程序是这样的: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();
}
}}
预期结果是输出一个表格,看了半天觉得程序没什么问题,但是编译到最后什么结果都没有,请大家帮我看一下,先在这里说一声谢谢了!
* @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();
}
}}
预期结果是输出一个表格,看了半天觉得程序没什么问题,但是编译到最后什么结果都没有,请大家帮我看一下,先在这里说一声谢谢了!
解决方案 »
- java正则表达式的问题
- jvm报异常!不知道应不影响服务?
- 问一个很简单的问题.急!!!
- 大家好,第一次提问,希望能得到大家指点,RandomAccessFile文件的问题!虚心向大家请教!
- 请用正则表达式找出不是csdn的其他单词和数字,一定要用正则表达式才行。
- 关于J2SE多媒体一些问题
- 求一个简单的算法!!!
- JAVA 怎样子才能最快的学会吃透
- jdbc-odbc桥的使用,请高手指教 ,一定给分!!!!!!!!!!!
- can not access directory?
- 我和老婆打赌,赢了就嫁我,支持就给分啊,谢谢大家了
- [130分]java的socket怎么上sock5代理?怎么设置代理用户和密码?
改成for(int j=0;j<balances[i].length;j++)
你没有j++.运行程序已经死循环了..
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?
? 楼主请问System.out.printf("%10.2f",b);的printf是什么啊?你编译的通吗?-----------------------------------------------------------------------------------
关于找不到print()和printf()的问题我写了篇随笔.在我blog上,自己看了.http://www.blogjava.net/ky1in/archive/2006/07/19/59089.html
汗,这个也掉