Thread: Fixing an error

    #1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    37
    Rep Power
    3

    Fixing an error


    Code:
    import java.util.*;
    
    public class GradeCalculator {
        public static void main(String[] args) {
        	
        	Scanner console = new Scanner(System.in);
        	
    System.out.print("Enter number of students: ");
    int StudentNum = console.nextInt();
    
    for (int i = 1; i =< StudentNum; i++) {
    System.out.print("Enter average for student: " + i);
    double StuAve = console.nextDouble();
    System.out.println("Student " + i + " average is : " + calculateGrade(StuAve));				    
    }
        }			    
    public static String calculateGrade(double average) {
        	
            String grade;
    
            if (average >= 90) {
                grade = "A";
            } else if (average >= 80) {
                grade = "B";
            } else if (average >= 70) {
                grade = "C";
            } else if (average >= 60) {
                grade = "D";
            } else {
                grade = "F";
            }
            return grade;
    }
    }
    I'm getting errors (it's pointing to my for loop but I don't know if that's the true cause of the errors) and I'm not sure how to fix them.
  2. #2
  3. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348
    I'm getting errors
    Please copy and paste here the full text of the error messages that include the source line numbers and the error text.
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    37
    Rep Power
    3
    Originally Posted by NormR
    Please copy and paste here the full text of the error messages that include the source line numbers and the error text.
    C:\Users\owner\Desktop\GradeCalculator.java:11: error: > expected
    for (int i = 1; i =< StudentNum; i++) {
    ^
    C:\Users\owner\Desktop\GradeCalculator.java:11: error: ';' expected
    for (int i = 1; i =< StudentNum; i++) {
    ^
    C:\Users\owner\Desktop\GradeCalculator.java:11: error: illegal start of expression
    for (int i = 1; i =< StudentNum; i++) {
    ^
    3 errors
  6. #4
  7. Contributing User
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Aug 2010
    Location
    Eastern Florida
    Posts
    3,714
    Rep Power
    348
    The =< operator is not valid. Check the list of valid operators:
    http://docs.oracle.com/javase/tutori...bolts/op2.html
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2012
    Posts
    37
    Rep Power
    3
    Originally Posted by NormR
    The =< operator is not valid. Check the list of valid operators:
    http://docs.oracle.com/javase/tutori...bolts/op2.html
    I see what I did there. Thanks for the help.

IMN logo majestic logo threadwatch logo seochat tools logo