Having some problems trying to run this program.
How do I get all of the arrays to execute?
How do I properly output the information correctly?
Any help would be appreciated. Thank you in advance.
Here are the requirements:
Your program should read a file with 3 columns and 30 rows of data....
Each column should go into a separate array.
Once the data is read in, your program should display a summary for each column including:
- the minimum value and the row at which this occurs
e.g. 95.7at row 1 for the first column
● the maximum value and the row at which this occurs
● the average
the sum.
CODE
package ASSIGN3;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class a3 {
/**
* @param args
*/
public static void main(String[] args) throws FileNotFoundException {
final String INPUTFILE = "src/ASSIGN3/colunms.txt";
/*
*/
Scanner inFile = new Scanner( INPUTFILE );
String header = inFile.nextLine();
final int COLUMN_COUNT = 30;
double[] array1 = new double[ COLUMN_COUNT ];
double[] array2 = new double[ COLUMN_COUNT ];
double[] array3 = new double[ COLUMN_COUNT ];
for(int i = 0; i < COLUMN_COUNT; i++) {
array1[i] = inFile.nextDouble();
array2[i] = inFile.nextDouble();
array3[i] = inFile.nextDouble();
}
inFile.close();
double sum = 0.0;
for(int i=0; i<array1.length; i++)
sum+=array1 [i];
double average = sum / array1.length;
double max= array1[0];
int index = 0;
for(int i=1; i<array1.length; i++){
if (array1 [i]> max)
max = array1 [i];
index = i;
}
System.out.println("max is x[" + index + "] = " + array1[index]);
double min = array1[0];
for(int i = 1; i < array1.length; i++) {
if(array1[i] < min) {
min = array1[i];
index = i;
}
}
System.out.println("min is x[" + index + "] = " + array1[index]);
System.out.println( header );
System.out.printf("The information in array1 is: %.2f inches%n" +sum + average + max + min + index);
System.out.printf("The information is array2 is: %.2f inches%n" +sum + average + max + min + index);
System.out.printf("The information is array3 is: %.2f inches%n" +sum + average + max + min + index);
}
}
This post has been edited by bigticket61: 13 Oct, 2008 - 07:41 PM