Skip to main content
fixed a code bug
Source Link
Daniel Gabriel
  • 4k
  • 2
  • 29
  • 40

It's a good idea to initialize your values to the opposite of what they represent before going into the loops.

int low = Integer.MAX_VALUE; int high = Integer.MIN_VALUE; 

But a better solution would be to do everything in the first loop:

int length = 12; for (int count = 0; count < length; count++){ System.out.println("Please Enter in the score: "); int value = inputTest.nextInt(); if (value < low) { low = value; } if (value > high) { high = value; } totaltotalScores += value; } average = (totalScores * 1.0) / length; 

It's a good idea to initialize your values to the opposite of what they represent before going into the loops.

int low = Integer.MAX_VALUE; int high = Integer.MIN_VALUE; 

But a better solution would be to do everything in the first loop:

int length = 12; for (int count = 0; count < length; count++){ System.out.println("Please Enter in the score: "); int value = inputTest.nextInt(); if (value < low) { low = value; } if (value > high) { high = value; } total += value; } average = (totalScores * 1.0) / length; 

It's a good idea to initialize your values to the opposite of what they represent before going into the loops.

int low = Integer.MAX_VALUE; int high = Integer.MIN_VALUE; 

But a better solution would be to do everything in the first loop:

int length = 12; for (int count = 0; count < length; count++){ System.out.println("Please Enter in the score: "); int value = inputTest.nextInt(); if (value < low) { low = value; } if (value > high) { high = value; } totalScores += value; } average = (totalScores * 1.0) / length; 
Source Link
Daniel Gabriel
  • 4k
  • 2
  • 29
  • 40

It's a good idea to initialize your values to the opposite of what they represent before going into the loops.

int low = Integer.MAX_VALUE; int high = Integer.MIN_VALUE; 

But a better solution would be to do everything in the first loop:

int length = 12; for (int count = 0; count < length; count++){ System.out.println("Please Enter in the score: "); int value = inputTest.nextInt(); if (value < low) { low = value; } if (value > high) { high = value; } total += value; } average = (totalScores * 1.0) / length;