for loop - Upside-down triangle of numbers i Java -


i'm beginner java , can't figure out how print upside down triangle of numbers. numbers should decrease in value 1 each row. ex. number of rows; 6 print:

666666 55555 4444 333 22 1 

so far came with; (int nr scanned input user)

for (int = 1; <= nr; i++) {      (int j = 1; j <=nr; j++)      {          system.out.print(nr);      }     nr--;      system.out.println();  } 

by having nr--; loop gets shorter , cant figure out how keep loop going "nr"-times, yet still decreasing amount of numbers printed out.

you right in need write loop print line each number, starting @ nr , decreasing 1 until 0. have print variable number of numbers @ each line. that, nested loop used print number amount of times necessary.

since start printing @ nr , decrease until reach 1, try writing outer loop decrements rather increments. use nested loop print number required number of times. example:

for (int = nr; > 0; i--) {     (int j = 0; j < i; j++) {         system.out.print(i);     }     system.out.println(); } 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -