よし、文字列入力だけでなく、可変数の入力を持つメソッドを必要とするこの割り当てを取得しました。入力はすべてスキャナの 1 行にある必要があり、メソッドは入力された値の数、平均値、最大値、最小値、および入力された文字列を返す必要があります。
これは、ターミナル ウィンドウが次のように表示される例です。
Please enter the name of the course: CourseNameHere
Please enter the scores for CSC 201 on a single line and type a -1 at the end
71 02 81 44 84 17 38 11 20 05 93 -1
The course name : CourseNameHere
Number of Scores : 11
The Average Score : 42.37
The Minimum Score : 02
The Maximum Score : 93
平均スコアは小数点以下 2 桁に四捨五入する必要があります (これは処理できると思います)。私にとって唯一の問題は、可変数の入力を 1 行でスキャンすることと、プログラムに入力数をカウントさせる方法です。入力の間にEnterキーを押していない場合。これは私がこれまでに持っているものですが、ここからどこへ行くべきかわかりません。連続した値を要求することはできますが、それらはすべて同じ行にあるわけではありません
public static int calculate(int again)
{
Scanner input = new Scanner(System.in);
int numberOfValues = 0;
int max = -9999;
int min = 100000;
int sum = 0;
double value;
System.out.print("What is the name of the course you wish to evaluate? : ");
String courseName = input.next();
System.out.println("Please enter the scores for the class, press enter between each value." + "\n" + "Enter -1 to finish and calculate.");
for(value = 0; value != 1; numberOfValues++)
{
value = input.nextDouble();
sum += value;
}