Javaクラス用の簡単なプログラムを書こうとしていて、先生に助けを求めましたが、これは遠隔学習クラスであり、その方向からの助けはあまり得られません. だからここにいます。
私たちが解決するように求められた問題は、(1) ユーザーに数値を尋ねる、(2) ユーザーが定義したすべての数値の合計を見つける、(3) これらの数値の平均を見つける、(4) というプログラムを作成することです。その後、それらをユーザーに戻します。
番号は、完了したものを並べるためだけでなく、呼び出される個別のモジュールでなければならないためにも使用します。
while ステートメントの実行中に userNum 変数を更新するにはどうすればよいですか。現在、そうではありません。または、見落としているこれを行う簡単な方法があります。どんな助けでも大歓迎です。ありがとうございました。
public class P2 {
public static void main(String[] args) {
int userNumCount = 1;
double userNum = input();
double userSum = sum(userNum);
double userAverage = average(userSum, userNumCount);
sum(userNum);
while (userNum != 0 && sum(userNum) <= 100){
++userNumCount;
output(userSum, userAverage);
input();
sum(userNum);
average(userSum, userNumCount);
}//end else
while (userNum != 0 && sum(userNum) >=100){
++userNumCount;
JOptionPane.showMessageDialog (null, "Warning, your sum is currently over 100!!!!!");
output(sum(userNum), userAverage);
input();
sum(userNum);
average(userSum, userNumCount);
}//end else
if (input() == 0){
output(userSum, userAverage);
JOptionPane.showMessageDialog (null, "Thank you for using this program have a nice day.");
}//end else if
}//end main module
public static double input(){
String userNumString;
userNumString = JOptionPane.showInputDialog("Please enter your number or input 0 to end the program.");
double userInput = Double.parseDouble (userNumString);
return userInput;
}//end input module
public static double sum(double userNum){
double userSum =+userNum;
return userSum;
}//end sum module
public static double average (double userSum, int userNumCount){
double userAverage = userSum/userNumCount;
return userAverage;
}//end average module
public static void output (double userSum, double userAverage){
JOptionPane.showMessageDialog (null, "The sum of the numbers input so far is: " + userSum + ". And the Average is " + userAverage + "." );
}//end output module
}//end class