这是我的代码
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Collections;
import java.util.Scanner;
import java.util.Arrays;
public class runsCreated {
public static void main(String[] args) throws FileNotFoundException {
String firstName = "";
String lastName = "";
int hits = 0;
int walks = 0;
int caughtStealing = 0;
int stolenBases = 0;
int atBats = 0;
int totalBases = 0;
double runsCreated = 0.0;
double[] runsCreatedList = new double[40];
double[] sortedList = new double[40];
String[] nameList = new String[40];
Scanner console = new Scanner(System.in);
//Asks user for input file name
System.out.println("Input File Name:");
String inputFileName = "//Users//Mitchell//Desktop//baseballinput.txt"; //console.next();
//inputFile will take input from stored input file
File inputFile = new File(inputFileName);
//in will take input from user defined source
Scanner inFile = new Scanner(inputFile);
int i = 0; //counter
while(inFile.hasNext()) {
lastName = inFile.next();
firstName = inFile.next();
hits = inFile.nextInt();
walks = inFile.nextInt();
totalBases = inFile.nextInt();
stolenBases = inFile.nextInt();
caughtStealing = inFile.nextInt();
atBats = inFile.nextInt();
runsCreated = ((hits + walks - caughtStealing) * (totalBases + (.55 * stolenBases)) / (atBats + walks));
runsCreatedList[i] = runsCreated;
sortedList[i] = runsCreatedList[i];
System.out.print(nameList[i] + ":" + " " + /*will be sortedList[i]*/runsCreatedList[i]);
i++;
}
sortedList[i] = Arrays.sort(sortedList);
inFile.close();
}
}
我在sortedList[i] = Arrays.sort(sortedList);
上收到错误消息,指出它无法从void
转换为double
。我知道它应该是double
我无法弄清楚如何修复它。任何帮助,将不胜感激。