-2
私は以前これを別のプロジェクトでやったことがありますが、私はこのプロジェクトでどのように行うのか分かりません。別の方法で出力を計算し、mainメソッドからコンソールに出力する必要があります。私はこれがおそらくあなたの大部分にとっては本当に簡単だと知っていますが、私は昨日コーディングを始めましたので、これを学んだことはありません。メソッドに情報を転送してから印刷のメインメソッドに戻す方法はありますか?
マイコード:
import java.util.Scanner; // This allows for the use of the scanner in the class
public class SavingsAccount // Start of class
{
public static void main(String[]args) // Start of main
{
double P; // These store the amounts that will be used in the accruing interest formula
double i;
double n;
double S = 0;
int timesLooped = 0;
Scanner readConsole = new Scanner(System.in); // This is the scanner
System.out.println("I am a savings account interest calculator."); // Prompts the user for input
System.out.println("How much money have you deposited?");
P = readConsole.nextDouble();
S = P;
System.out.println("Now, what is the annual interest rate? (i.e. .05)");
i = readConsole.nextDouble();
System.out.println("Finally, how long do you plan on having the money in the account?");
n = readConsole.nextDouble();
while (timesLooped <= n)
{
S = S + (P * i);
timesLooped += 1;
}
System.out.println("Your balance in that time span is " + S + "."); // Tells you your ending balance
}
}
'return'キーワードは基本的な概念です。 – Li357
私がしようとしていることの正確な記述は、「別々のメソッドの中で計算と変換を行う」であり、メインメソッドのメソッドに必要な情報を渡します。 " –
ええ私は他の人からそれを覚えていますが、私はこのプロジェクトでどのように使うべきかわかりません –