如何使此循环的结果成为不同结果的数组:
for (int i = 1; i <= years; i++) {
double newbalance = account.getBalance() * rate;
account.deposit(newbalance);
String test = String.valueOf(account.getBalance()) + "\n";
result.append(test);
}
例如:
如果用户放置了10
年,则会给出10个结果。
我需要:
谢谢。
答案 0 :(得分:0)
String[] result = new String[years];
for (int i = 1; i <= years; i++) {
double newbalance = account.getBalance() * rate;
account.deposit(newbalance);
String test = String.valueOf(account.getBalance());
result[i-1] = test;
}
如果要从结果中删除数据,可以再次初始化结果:
result = new String[years];