Share

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

loop programming exercises in java, c++, python and javascript

Java

for (int i=1; i<=5; i++) {
		 for (int j=5; j>=i; j--) {
			 System.out.print(" ");
		 }
		 for (int k=1; k<=i; k++) {
			 System.out.print("*");
		 }
		 System.out.print("\n");
	 }

C++

for (int i=1; i<=5; i++) {
		 for (int j=5; j>=i; j--) {
			 cout<<" ";
		 }
		 for (int k=1; k<=i; k++) {
			 cout<<"*";
		 }
		 cout<<endl;
	 }

Javascript

let height=5;
  
   for (var i = 1; i <= height; i++) {
     var row = '';
     
     for (var j = 1; j <= (height - i); j++) {
       row += ' ';
     }
     
     for (var k = 1; k <= i; k++) {
       row += '*';
     }
     
     console.log(row);
   }