Share

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

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

Java

for(int i=5;i>=1;i--){
	for(int j=1;j<=i;j++){
		System.out.print(i);
	}
	System.out.println();
}

Python

for x in range(5,0,-1):
    for y in range(0,x):
        print(x,end="")
    print()

C++

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

Javascript

for (let i = 5; i >= 1; i--) {
   let eachLine="";
       for (let j = 1; j <= i; j++) {
               eachLine+=i+"";
           }
           eachLine=eachLine.trim();
           console.log(eachLine);
       }