Why is the else not printing

Question from akira💖🌻#6298

hello i have a small small problem

package HelloJaxa;
import java.util.*;
public class Main {
    public static void main(String[] args) {
        Scanner scan=new Scanner(System.in);
        System.out.print("Enter 10 Grades--> ");
        int Number=0;
        int counter90=0;
        int counterless=0;
        if (Number>=0 && Number<=100) {
            for (int i = 0; i < 10; i++) {
                Number = scan.nextInt();
                if (Number >= 90)
                    counter90++;
                if (Number > 60 && Number < 90)
                    counterless++;
            }
            System.out.println("Grades that equal 90 or more-->"+counter90);
            System.out.println("Grades that are between 60 and 90--> "+ counterless);
        }
        else
            System.out.println("Error!");
    }}

why is the else not printing when i input a number thats <0 or >100

First, put the {} around the else. Sometimes that can be the whole issue. Try not to omit the {} even though its technically allowed.

And you will never reach the else since you check if the number is between 0 and 100 before entering the loop where you ask for input.

You never return to that check again so it only runs once and sees 0.

what do i do now ?

Move your check inside your for loop


<- Index