dimanche 13 août 2023

What is the last value of b which breaks the loop? ( Is it -1 if I am not wrong?? )

class exp{
public static void main(String arr[]){

for(int b=3;b>=0;b--) {
System.out.println("");

for(int a=0;a<=b;a++)  {
System.out.print("*");
    }
}

    }
}

It is an asterisk pattern, I understand this code and as per my understanding that last value of b should be -1 so that the final outer loop breaks and stops the printing of the pattern. I even tried to print the value of b but understood that it won't work due to the scope limitations. Can someone please confirm me the value of final value of b here in this code.

Aucun commentaire:

Enregistrer un commentaire