java - Do not understand how loop is determining how many asterisks to print -


i beginner @ learning java. have stumbled upon problem can not figure out. how loop in code determining how many asterisk print out. keep looking @ part of code..

asterisk < myarray[counter] 

could please explain in simplest of terms how works, because every time think of counter, see nothing index pointing @ time in loop.

public class main {      public static void main(string[] args) {          int[] myarray = {12, 7, 9, 11, 23};          system.out.println("value distribution");          //start of outer loop         for( int counter = 0; counter < myarray.length; counter++){              //start of inner loop             for( int asterisk = 0; asterisk < myarray[counter]; asterisk++)                  system.out.print("*");              system.out.println();          }//end of outer loop 

simply put

asterisk < myarray[counter] 

means it's checking whether amount of asterisks less value myarray[counter].

so when have counter = 0 have myarray[counter] = 12.

which means in inner loop, print asterisks until asterisk no longer lesser 12. thus, going 0-11 print 12 asterisks.


Comments

Popular posts from this blog

javascript - Thinglink image not visible until browser resize -

firebird - Error "invalid transaction handle (expecting explicit transaction start)" executing script from Delphi -

mongodb - How to keep track of users making Stripe Payments -