私は以下のコードを使用して複利プログラムを実行していますが、なぜ機能していないのかわかりません。 Eclipseは私にエラーメッセージを出しています: "ローカル変数の値は使用されていません。"警告は声明の中で計算された量が使用されていない中であることを通知することである化合物関心プログラム構文エラー
for (int i = 1; i<=20; i++){
double amount = deposit * Math.pow(1+(rate/compound), years*compound);
System.out.println(amount); // just a type of use
}
-
package loops;
public class CompoundInterest {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("How much did you put into the bank?");
double deposit = IO.readDouble();
System.out.println("What is the bank's interest rate?");
double rate = IO.readDouble();
System.out.println("How many times will it compound?");
double compound = IO.readDouble();
System.out.println("How many years?");
double years = IO.readDouble();
for (int i = 1; i<=20; i++){
double amount = deposit * Math.pow(1+(rate/compound), years*compound);
}
}
}
決して出力を出すことはないので、あなたの計算がすべて電子移動を無駄にしていることを警告しています。 – bmargulies
ええ、私はちょうどそれを実現しました。ありがとうございました。 – Chris
同じ計算を20回繰り返すのはなぜですか?使用した数式を使用すると、計算を一度行うだけで済みます。 –