私の問題は、このコードが返されず、呼び出したときの値です。メソッドとループ
別のtxtファイルから値のセットを読み込んで答えを出力する必要があります。 それから別の空のテキストファイルに印刷できるようにする必要があります。 txtファイル内
値(イン間の線のスペースなし)です:
1 2 3 4 5 6
4 5 6
7.5 8.5 9
8.1 9.2 10.3
ソースコードを次のように
public class Lab5d {
public static void main(String args[]) {
// Scan the input
Scanner scan = new Scanner(System.in);
String line = scan.nextLine();
Scanner lineScan = new Scanner(line);
// Process each line separately
// If the next token is a double, assume there is an input line
while (scan.hasNextDouble()) {
processLine(line);
}
}
public static void processLine(String line) {
Scanner scan = new Scanner(System.in);
Scanner lineScan = new Scanner(line);
double a = lineScan.nextDouble();
double sum;
double product;
double count;
double average;
sum = 0;
count = 0;
product = 1;
while (lineScan.hasNext()) {
sum = sum + a;
product = product * a;
++count;
}
double ave = sum/count;
System.out.printf("sum= %.1f, product= %.1f, ave= %.1f, count= %.1f%n", sum, product, ave, count);
}
}
は誰でも助けることはできますか?
私はいくつかのデバッグを行うことをお勧めします。あなたがデバッガを持っていて、それを使う方法を知っていれば、それは人生を楽にします。 「不良者のデバッガ」には常にオプションがあります。診断出力文をキーポイントに一時的に挿入して、プログラムの実行場所と重要な変数の値を表示します。 –