0

I'm making a simple program in java for school where you input the name and score for 3 students and then it returns the grade however when it loops the first time it no longer asks for the grade. my output ends up looking like this
https://i.stack.imgur.com/QyMjp.jpg

this is the code

                while (i <3)
    {
        
        System.out.println("please enter the students name:    ");
            name=sc.nextLine();
        System.out.println("please enter the students grade:    ");     
            score=sc.nextInt();
        
        if(score>=80)       
        {   
            grade='A';
        }
        else if(score>=70 && score<80)
        {
            grade='B';
        }
        else if(score>=50 && score<70)
        {
            grade='C';                  
        }
        else {
            grade='F';
        }

        System.out.println(name + " got a score of " + score + " and a grade of " + grade); 
        System.out.println("================================================================");//separate each output so its easier to read
        i++;
    }   
blu
  • 11
  • 1
  • 2
    Please add complete code here, to help you better. – Gaurav Jeswani Sep 30 '20 at 13:29
  • sc.nextLine(); <- this reads from the input. If you don't have more than 3 lines of input. There won't be anything more to read. So for your loop to work, you also need to keep reading in new lines. – GamingFelix Sep 30 '20 at 13:30

0 Answers0