ここで、私はテキストブックの練習コードから作成しようとしている私のコードです。この質問では、ユーザーに投資金額と金利を入力するよう促すJavaコンソールプログラムを作成するように求められました。さらに、プログラムはこれらの入力を使用して将来の価値を計算し、リストする(私は5期間までそれをやっている)。たとえば、金額に500、金利に1などの入力を使用すると、プログラムは、(期間1から5まで)505.00,510.05,515.15,520.30,525.51で表示されます。すべてのヒントや助けをいただければ幸いです!^-^プログラムで将来の値を正しく実行するにはどうすればよいですか?
import java.util.Scanner;
public class FutureValues {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
String inputString;
char letter = 'c';
// Prompt the user to enter investment amount
while(letter == 'c') {
System.out.print("Enter your investment amount: ");
int InvestmentAmount = input.nextInt();
// Prompt the user to enter interest rate
System.out.print("Enter the interest rate (%): ");
int InterestRate = input.nextInt();
System.out.println(" ");
// Display the header
System.out.println("The future values are: ");
System.out.println(" ");
// Display "Period" title and "rate" title
System.out.println("Period " + InterestRate + "% ");
System.out.println("\n------ ------");
// Display table body
for (int h = 1; h <= 5; h++) {
System.out.print(h);
System.out.printf(" %4.2f", (double) (InterestRate) + 1 * InvestmentAmount);
System.out.println(" ");
}
System.out.println(" ");
System.out.print("Enter c to continue or any other character to quit: ");
String character = input.nextLine();
inputString = input.nextLine();
letter = inputString.charAt(0);
}
}
}
のですか? –
私はコードを最大5期間の金額を計算するようにしようとしているし、それを得ることができるのは、それぞれの5期間ごとに同じ値を実行することです(そして、そのうちの1つではありません)プログラミングに新しいが、私は学びたいと思っている。 –
あなたは何が化合物の関心を知っていますか? –