Question: Any one can help me fix this error? the program crashes when there is no date entered Your Program's Output Exception in thread main java.lang.ArrayIndexOutOfBoundsException:

Any one can help me fix this error?

the program crashes when there is no date entered

Your Program's Output

Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 0 at arrayOperations.main(arrayOperations.java:41)  (Your program crashed here.)

?line 41: String fileName = args[0];

import java.io.File; import java.io.FileNotFoundException; import java.util.Scanner; import java.util.Formatter; public class arrayOperations {

public double getTotal(double[] array){ double sum=0.0; for(int i=0; i

public double getAverage(double[] array1){ double average=getTotal(array1)/array1.length; return average; }

public double getHighest(double[] array2){ double max = array2[0]; for(int i=0; i

}

public double getLowest(double[] array2){ double min = array2[0]; for(int i=0; i array2[i]){ min = array2[i]; } } return min; } public static void main(String[] args) throws FileNotFoundException { String fileName = args[0]; File file = new File(fileName); if(file.exists()) { Scanner fileInput = new Scanner(file); int n = 0; while(fileInput.hasNextDouble()) { n++; fileInput.nextDouble(); if (n==0){ System.out.printf("Usage: java ArrayOperations "); fileInput.nextDouble(); n++;

} else{ continue; } } double arr[] = new double[n]; Scanner scan = new Scanner(file); for(int i=0; i

} } }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The issue youre encountering is due to the program crashing when no commandline argument specifically a file name is provided leading to an ArrayIndex... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!