My program is skipping the first line of my .txt file. Here is where my code is supposed to read from the .txt file.
static int getPints(int[] pints) throws IOException {
Scanner inputFile = new Scanner(new File("BloodInFile.txt"));
int count = 0;
while (inputFile.hasNext()) {
pints[count] = inputFile.nextInt();
count++;
}
return pints[count];
}
It should be reading 7 integers, but I only get 6 of them to be read. The rest of the code works, but I am not sure how to get it to read the first integer.
This is the rest of my code:
static int getPints(int[] pints) throws IOException {
Scanner inputFile = new Scanner(new File("BloodInFile.txt"));
int count = 0;
while (inputFile.hasNext()) {
pints[count] = inputFile.nextInt();
count++;
}
inputFile.close();
return pints[count];
}
static double getAverage(int pints[], int MAX_HOURS) {
int counter;
double totalPints = 1;
double averagePints;
for (counter = 1; counter < MAX_HOURS - 1; counter++) {
System.out.println("pints:" + pints[counter]);
totalPints = totalPints + pints[counter];
}
averagePints = totalPints / (MAX_HOURS - 2);
System.out.println("Total pints: " + totalPints);
return averagePints;
}
static double getHigh(int pints[], int MAX_HOURS) {
int index = 1;
double highest = pints[index];
for (index = 1; index < MAX_HOURS - 1; index++) {
if (pints[index] > highest) {
highest = pints[index];
}
}
return highest;
}
static double getLow(int pints[], int MAX_HOURS) {
int index = 1;
double lowest = pints[index];
for (index = 1; index < MAX_HOURS - 1; index++) {
if (pints[index] < lowest) {
lowest = pints[index];
}
}
return lowest;
}