-1

I'm trying to print out only certain integers which are larger than 76 but I can't seem to figure it out. The output just prints all the integers stored in the array

class over76 {
public static void main(String[] args) {
    int a[] = new int[]{12, 77, 92, 55, 24, 65, 41, 13,  76 , 90};

    for (int i = 0; i < a.length; i++){
        if(a[i]>76);
        System.out.println(a[i]);
    }

}

}

  • 1
    Here, `if(a[i]>76);`, the semicolon `;` is short-circuiting your if block, turning it into `if (a[i] > 76) { ; }`. Get rid of it and do: `if (a[i] > 76) { System.out.println(a[i]); }` instead. Also, when just starting out, use curly braces for all if/else blocks, all loops. – Hovercraft Full Of Eels May 21 '22 at 14:40
  • 1
    You're welcome. Please note edit to my comment -- use curly braces for all blocks when new to Java. – Hovercraft Full Of Eels May 21 '22 at 14:44

0 Answers0