I need to find the sum, count of, number of evens, number of odds, largest, smallest, and average of the numbers of the scanned file. I've done everything except largest/smallest. When the program runs, the largest/smallest equals the count instead of producing the largest/smallest value the count encounters.
EDIT: I understand that largest/smallest are being compared to count. I now understand that mistake. I don't understand how to find the smallest/largest value that count encounters.
Here is what I've done: NOTE: All code before while loop was prewritten by my professor and that code cannot be tampered with or altered in any way. Not allowed to use arrays either.
int count=0,sum=0, largest=Integer.MIN_VALUE,smallest=Integer.MAX_VALUE, evens=0, odds=0;
double average=0.0;
while (infile.hasNext())
{
count += 1;
sum += infile.nextInt();
average = sum/count;
if (count > largest)
largest = count;
if (count < smallest)
smallest = count;
if (sum%2 != 0)
odds++;
else
evens++;
}
infile.close();