Share

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

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

Java



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

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

C++

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

Javascript

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