Hey
This is probably something easy. In fact, it definitely is. Still new to Java so ignore lack of arrays and better ways of doing it, as I'm only 172 pages into a 1300 page college book!!
Basically, what the code is to do is to get the user to enter a number of students. The user then enters a name and a score associated with this name (for the purpose of the code I am using 5 students - Chris 17, Tony 25, Zach 3, Michelle 20, God 99). This code should then output the highest and lowest student - in the case of my examples, God being the highest with 99 and Zach the lowest with 3.
However, the for loop is terminating once I enter the second student, which it should allow me to enter a total of 4 users (1 user entered before the for loop and 4, in the case of this example, during the for loop. It does work, in that it gives me the highest and lowest correctly, but only of the two entries.
Any help appreciated.
import java.util.Scanner; public class lowHighStudent { /** * @param args */ public static void main (String args[]) { Scanner input = new Scanner(System.in); System.out.print("Enter number of students: "); int noStudents = input.nextInt(); System.out.print("Enter Student Name: "); String studentHigh = input.next(); System.out.print("Enter Student Score: "); int scoreHigh = input.nextInt(); int scoreLow = 99999, temp = 0; String studentLow = ""; for(int i = 0; i < noStudents - 1; i++); { System.out.print("Enter Student Name: "); String student1 = input.next(); System.out.print("Enter Student Score: "); int score1 = input.nextInt(); if (score1 > scoreHigh) { temp = scoreHigh; studentLow = studentHigh; scoreHigh = score1; studentHigh = student1; scoreLow = temp; } else if (score1 < scoreLow) { scoreLow = score1; studentLow = student1; } } System.out.print("Highest Student is " + studentHigh + " with a score of " + scoreHigh); System.out.println("Lowest Student is " + studentLow + " with a score of " + scoreLow); } }