My code needs to print certain results to a file if the user types something, and if they type nothing just print it to the screen. I wrote the code, and am including it below, but once my program prompts the user it doesn't do anything and I don't understand why. I know the code is long, but is fairly logically laid out. If anyone knows why please give me some insights, Thank You.
import java.util.*; import java.io.*; public class Project4{ public static void main(String[] args) throws FileNotFoundException { Scanner input = new Scanner(System.in); System.out.print("File Name:"); String fileName = input.nextLine(); Scanner console = new Scanner(new File(fileName)); int totalNumbers = console.nextInt(); double[] filearray; filearray = new double[totalNumbers]; for (int i = 0; i < totalNumbers; i++) filearray[i] = console.nextDouble(); System.out.print("Output [type a file name, or push return"); System.out.print(" to output to screen]: "); String s = input.next(); System.out.print("There are " + totalNumbers); System.out.println(" numbers in your input file"); if (s.length() == 0){ printResults(filearray); } else { writeResultsToFile(filearray); } Arrays.sort(filearray); } public static double calculateMax(double[] filearray){ double maximum = filearray[0]; for (int i = 1; i < filearray.length; i++){ if (filearray[i] > maximum){ maximum = filearray[i]; } } return maximum; } public static double calculateMin(double[] filearray){ double minimum = filearray[0]; for (int i = 1; i < filearray.length; i++){ if (filearray[i] < minimum){ minimum = filearray[i]; } } return minimum; } public static double calculateMean(double[] filearray){ double sum = 0; //calculates sum for (int i = 0; i < filearray.length; i++){ sum = sum + filearray[i]; } //calculates average double mean = (sum / filearray.length); return mean; } public static double calculateMedian(double[] filearray){ int middle = (filearray.length+1)/2; if (filearray.length%2 == 1) { // Odd number of numbers -- return the middle one. return filearray[middle]; } else { // Even number -- return average of middle two // Must cast to double before division. return (filearray[middle-1] + filearray[middle]) / 2.0; } } public static double calculateMode(double[] filearray){ double maxValue = -1; int maxCount = 0; for (int i = 0; i < filearray.length; i++){ //counts number of times number is in array int count = 0; for(int j = 0; j < filearray.length; j++){ if(filearray[j] == filearray[i]){ count++; } } //remember which was max if (count > maxCount){ maxValue = filearray[i]; maxCount = count; } } return maxValue; } static double calculateStandardDeviation(double[] filearray, double meanOfArray){ double squareOfDeviations = 0; for(int i = 0; i < filearray.length; i++){ double diff = filearray[i] - meanOfArray; squareOfDeviations = squareOfDeviations + (diff * diff); } double deviance = (squareOfDeviations/filearray.length); return deviance; } public static void printResults(double[] filearray){ double maximumOfArray = calculateMax(filearray); double minimumOfArray = calculateMin(filearray); double modeOfArray = calculateMode(filearray); double meanOfArray = calculateMean(filearray); double medianOfArray = calculateMedian(filearray); double standardDeviationOfArray = calculateStandardDeviation(filearray, meanOfArray); System.out.println("Max: " + maximumOfArray); System.out.println("Min: " + minimumOfArray); System.out.println("Mode: " + modeOfArray); System.out.println("Mean: " + meanOfArray); System.out.println("Median " + medianOfArray); System.out.println("Standard Deviation: " + standardDeviationOfArray); } public static void writeResultsToFile(double[] filearray) throws FileNotFoundException{ PrintStream output = new PrintStream(new File("results.txt")); double maximumOfArray = calculateMax(filearray); double minimumOfArray = calculateMin(filearray); double modeOfArray = calculateMode(filearray); double meanOfArray = calculateMean(filearray); double medianOfArray = calculateMedian(filearray); double standardDeviationOfArray = calculateStandardDeviation(filearray, meanOfArray); output.println("Max: " + maximumOfArray); output.println("Min: " + minimumOfArray); output.println("Mode: " + modeOfArray); output.println("Mean: " + meanOfArray); output.println("Median " + medianOfArray); output.println("Standard Deviation: " + standardDeviationOfArray); } }