在处理方法方面有问题。这是一个简单的程序,但我似乎无法将我的数据打印到终端上
下面是我的代码:
public class method
{
public static void main( String args[] )
{
double result = 0;
int i;
System.out.println("i" + "\t\t" + "m(i)");
System.out.println("-------------------");
//columns and header
}
public double theSum(int i, double result)
{
for(i=0; i < 21; i++)
{
System.out.print(i + "\t\t" + result + "\n");
result +=(double) (i + 1)/(i+2);
// computing the data
}
return result;
}
}一切都会编译,但我的输出只打印我的标题...我认为我的底层方法可能是错误的,但不确定在哪里。
Sample output:
1 0.5
2 1.16
...
19 16.40
20 17.35发布于 2014-02-06 11:53:45
您根本没有调用您的方法。
public static void main( String args[] )
{
double result = 0;
int i;
System.out.println("i" + "\t\t" + "m(i)");
System.out.println("-------------------");
//columns and header
double result = theSum(5,result); //Call the method
}另外,为什么需要传递变量i?您将在循环内将其重置为零。
https://stackoverflow.com/questions/21593618
复制相似问题