所以我一直對這個代碼一段時間了,我測試了它,並有0個錯誤之前添加的JOptionPane,然後我加入的JOptionPane和27-之間有38。所以,我清楚地做了一些錯誤的,我的JOptionPane,但我不知道,我只使用經驗大部分掃描器所以任何幫助,將不勝感激。謝謝!導入.txt文件到數組,輸出W /的對話框
import javax.swing.JOptionPane;
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class TestScores
{
public static void main(String args[]) throws IOException {
String filename = ("scores.txt");
File file = new File(filename);
Scanner inputFile = new Scanner(file);
while (inputFile.hasNextInt()) {
String line = inputFile.nextLine();
ArrayList<Integer> scores = new ArrayList<Integer>();
Scanner scanner = new Scanner(line);
scanner.useDelimiter(",");
while(scanner.hasNextInt()) {
scores.add(scanner.nextInt());
}
scanner.close();
}
}
public static int averageScore(int[] numbers) {
int total = 0;
for (int i : numbers) {
total += i;
}
return total/(numbers.length);
}
public static int modeOfScores(int[] numbers) {
int modeCount = 0;
int mode = 0;
int currCount = 0;
int currElement;
for (int candidateMode : numbers) {
currCount = 0;
for (int element : numbers) {
if (candidateMode == element) {
currCount++;
}
}
if (currCount > modeCount) {
modeCount = currCount;
mode = candidateMode;
}
}
return mode;
}
public static int lowestScore(int[] numbers) {
int lowest = numbers[0];
for(int i = 1; i > numbers.length; i++) {
if(numbers[i] < lowest) {
lowest = numbers[i];
}
}
return lowest;
}
public static int largestScore(int[] numbers) {
int largest = numbers[0];
for(int i = 1; i < numbers.length; i++) {
if(numbers[i] > largest) {
largest = numbers[i];
}
}
return largest;
}
JOptionPane.showMessageDialog (null, "The Average number is: " + total);
JOptionPane.showMessageDialog (null, "The Mode number is: " + mode);
JOptionPane.showMessageDialog (null, "The Lowest number is: " + lowest);
JOptionPane.showMessageDialog (null, "The Largest number is: " + largest);
}
編輯:這是我得到的所有錯誤,所有從JOptionPane的部分
TestScores.java:86: error: <identifier> expected
JOptionPane.showMessageDialog(null, "The Average number is: " +(averageScore));
^
TestScores.java:86: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Average number is: " +(averageScore));
^
TestScores.java:86: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Average number is: " +(averageScore));
^
TestScores.java:86: error: ')' expected
JOptionPane.showMessageDialog(null, "The Average number is: " +(averageScore));
^
TestScores.java:86: error: ';' expected
JOptionPane.showMessageDialog(null, "The Average number is: " +(averageScore));
^
TestScores.java:86: error: <identifier> expected
JOptionPane.showMessageDialog(null, "The Average number is: " +(averageScore));
^
TestScores.java:86: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Average number is: " +(averageScore));
^
TestScores.java:86: error: <identifier> expected
JOptionPane.showMessageDialog(null, "The Average number is: " +(averageScore));
^
TestScores.java:86: error: ';' expected
JOptionPane.showMessageDialog(null, "The Average number is: " +(averageScore));
^
TestScores.java:87: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Mode number is: " +(modeOfScores));
^
TestScores.java:87: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Mode number is: " +(modeOfScores));
^
TestScores.java:87: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Mode number is: " +(modeOfScores));
^
TestScores.java:87: error: ')' expected
JOptionPane.showMessageDialog(null, "The Mode number is: " +(modeOfScores));
^
TestScores.java:87: error: ';' expected
JOptionPane.showMessageDialog(null, "The Mode number is: " +(modeOfScores));
^
TestScores.java:87: error: <identifier> expected
JOptionPane.showMessageDialog(null, "The Mode number is: " +(modeOfScores));
^
TestScores.java:87: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Mode number is: " +(modeOfScores));
^
TestScores.java:87: error: <identifier> expected
JOptionPane.showMessageDialog(null, "The Mode number is: " +(modeOfScores));
^
TestScores.java:87: error: ';' expected
JOptionPane.showMessageDialog(null, "The Mode number is: " +(modeOfScores));
^
TestScores.java:88: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Lowest number is: " +(lowestScore));
^
TestScores.java:88: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Lowest number is: " +(lowestScore));
^
TestScores.java:88: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Lowest number is: " +(lowestScore));
^
TestScores.java:88: error: ')' expected
JOptionPane.showMessageDialog(null, "The Lowest number is: " +(lowestScore));
^
TestScores.java:88: error: ';' expected
JOptionPane.showMessageDialog(null, "The Lowest number is: " +(lowestScore));
^
TestScores.java:88: error: <identifier> expected
JOptionPane.showMessageDialog(null, "The Lowest number is: " +(lowestScore));
^
TestScores.java:88: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Lowest number is: " +(lowestScore));
^
TestScores.java:88: error: <identifier> expected
JOptionPane.showMessageDialog(null, "The Lowest number is: " +(lowestScore));
^
TestScores.java:88: error: ';' expected
JOptionPane.showMessageDialog(null, "The Lowest number is: " +(lowestScore));
^
TestScores.java:89: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Largest number is: " +(largestScore));
^
TestScores.java:89: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Largest number is: " +(largestScore));
^
TestScores.java:89: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Largest number is: " +(largestScore));
^
TestScores.java:89: error: ')' expected
JOptionPane.showMessageDialog(null, "The Largest number is: " +(largestScore));
^
TestScores.java:89: error: ';' expected
JOptionPane.showMessageDialog(null, "The Largest number is: " +(largestScore));
^
TestScores.java:89: error: <identifier> expected
JOptionPane.showMessageDialog(null, "The Largest number is: " +(largestScore));
^
TestScores.java:89: error: illegal start of type
JOptionPane.showMessageDialog(null, "The Largest number is: " +(largestScore));
^
TestScores.java:89: error: <identifier> expected
JOptionPane.showMessageDialog(null, "The Largest number is: " +(largestScore));
^
TestScores.java:89: error: ';' expected
JOptionPane.showMessageDialog(null, "The Largest number is: " +(largestScore));
^
TestScores.java:90: error: reached end of file while parsing
}
^
它總是有幫助的,包括錯誤/堆棧跟蹤。 – ChiefTwoPencils 2014-12-03 01:06:05
添加錯誤,謝謝大家的意見 – 2014-12-03 01:08:38