Making patterns in java with nested loops -


i'm having trouble figuring out last pattern in java assignment. know i'm close can't figure out here's code:

public static void main(string[]args){     system.out.println("pattern d:");     (int = 6; i>=1; i--) { // row         int x = 6; // counter?         (int j = 1; j<=i; j++){ //column             system.out.print("");             x--;         }          for(int k=1;k<=i;k++) {             system.out.print(x);         }          system.out.println();     } } 

i understand outer loop rows , inner columns, that's not part have wrong. pattern self right not out put of numbers. can't put output on here because won't format right. if copied code instead of line of 0,then 1, then, 2... etc, i'm trying 1 2 3 4 5 6 on top line, 1 2 3 4 5, next line , on...

you close correct pattern, added little much. general tip (not of time), when making these loop patterns can print these patterns using integers in loops. changed code little bit give pattern wanted. didn't need x counter because can use deepest nested loop's integer counter, in how adjusted code j because run 6 times on first 5 on second , on. part added 3rd nested loop. did exact same thing 2nd loop because both had condition of running while less i. here code; hope explanation helped.

public static void main(string[]args){     system.out.println("pattern d:");     (int = 6; i>=1; i--) { // row         (int j = 1; j<=i; j++){ //column             system.out.print(j);         }  system.out.println();     } } 

Comments

Popular posts from this blog

python - mat is not a numerical tuple : openCV error -

c# - MSAA finds controls UI Automation doesn't -

wordpress - .htaccess: RewriteRule: bad flag delimiters -