dimanche 17 mai 2020

How this following "if statement" really works with the multiple "OR" operator

I have little knowledge about the how the loops work.but the following program contain more then one loop and the if statement contain multiple OR operator.i am not sure how exactly the if statement works in this program, so some one please explain me.

public static void printSquareStar(int number) {
    if (number < 5) {
        System.out.println("Invalid Value");
    } else {
        //Rows
        for (int i = 1; i <= number; i++) {
            //Columns
            for (int j = 1; j <= number; j++) {
                if ((i == 1) || (i == number) || (j == 1) || (j == number) || (i == j) || (j == (number - i + 1))) {
                    System.out.print("*");
                } else {
                    System.out.print(" ");
                }

            }
            System.out.println();
        }
    }
}

Aucun commentaire:

Enregistrer un commentaire