【发布时间】:2017-07-25 03:35:43
【问题描述】:
我必须实现一个 digitSquareSum() 方法,我已经实现如下:
public int digitSquareSum(int n) {
int total;
if (n < 10) {
total = (int) Math.pow(n, 2);
return total;
} else {
total = (int) ((Math.pow((n %10), 2)) + digitSquareSum(n/10));
return total;
}
}
现在,我想创建一个方法,该方法将为 CSV 文件返回一个 Java File 对象,该文件由 1-500 的 digitSquareSum 填充,格式如下:
public File questionOne() throws Exception {
//code here
}
所以文件应该看起来像
1,1
2,4
.
.
500,25
我该如何解决这个问题?
【问题讨论】:
-
使用
java.io.FileWriter。