I have an assignment where i have to read int's in from a txt file and put them into categories and then output them. Getting a lump of errors can anyone tell me what im doing wrong? Also i need to ignore the first number in the file, how would i do this? Am i going about entirely the wrong way?
Code:import java.io.*; import java.util.Scanner; public class ClassGrades{ public static void main (int[] args){ int one = 0; int two = 0; int three = 0; int four = 0; int five = 0; int six = 0; int seven = 0; int eight = 0; File file = new File("grades.txt"); try{ Scanner scanner = new Scanner(file); while(scanner.nextInt()) { if(scanner.nextInt < 25) { one = one + 1}; else if(scanner.nextInt() > 24 && < 50) { two = two + 1}; else if(scanner.nextInt() > 49 && < 75) { three = three + 1}; else if(scanner.nextInt() > 74 && < 100) { four = four + 1}; else if(scanner.nextInt() > 99 && < 125) { five = five + 1}; else if(scanner.nextInt() > 124 && < 150) { six = six + 1}; else if(scanner.nextInt() > 149 && < 175) { seven = seven + 1}; else { eight = eight + 1}; System.out.println("[0 - 24]: "one""); System.out.println("[25 - 49]: "two""); System.out.println("[50 - 74]: "three""); System.out.println("[75 - 99]: "four""); System.out.println("[100 - 124]: "five""); System.out.println("[125 - 149]: "six""); System.out.println("[150 - 174]: "seven""); System.out.println("[175 - 199]: "eight""); } scanner.close(); } catch(FileNotFoundException e) {} } }
XI Wiki


