Share

loop programming exercises in java, c++, python and javascript —11 📎

Java

int i, j, number= 1, rows=4;
for(i=1; i <= rows; i++){
     for(j=1; j <= i; ++j){
         System.out.print(number);
 ++number;
     }
     System.out.print("\n");
 }

C++

int i, j, number= 1, rows=4;
	 
	 for(i=1; i &lt;= rows; i++){
		 for(j=1; j &lt;= i; ++j){
			 cout&lt;&lt;number;
	 ++number;
		 }
		 cout&lt;&lt;endl;
	 }

Javascript


var i, j, rows = 4, n = 1;
  
  for (i = 1; i &lt;= rows; i++){
     let eachLine="";
     for (j = 1; j &lt;= i; j++, n++){
         eachLine+=n+"";
     }
        console.log(eachLine);
 
}