0
Program to print the following pattern in java
h he hel hell hello I tried the following code ``` public class Pyramid{ public static void main(String[] args){ int i,j; String W="hello"; for(i=1;i<=4;i++) { for(j=1;j<=W.length();j++){ System.out.print(W); } System.out.print(j); } System.out.println(); } }
11 Antworten
+ 5
Param Siddharth Yes I know
+ 3
Alfred Monir Hugo Check again and try to do self
Edited
Pattern 2 in reverse order
+ 2
Thank you Mirielle🐶 [Inactive]
+ 2
🅰🅹 - ɪ'ᴍ ᴄʀɪᴍɪɴᴀʟʟʏ ɢᴏᴏᴅ! Ok i am trying and Thank you for your help
+ 2
My example using recursion
https://code.sololearn.com/cb7EGijOfyO4/?ref=app
+ 2
🅰🅹 - ɪ'ᴍ ᴄʀɪᴍɪɴᴀʟʟʏ ɢᴏᴏᴅ!, it can also be achieved using a single for loop:
https://code.sololearn.com/cQ78wy4trfI1/?ref=app
+ 1
🅰🅹 - ɪ'ᴍ ᴄʀɪᴍɪɴᴀʟʟʏ ɢᴏᴏᴅ! I tried this code after your help and got the answer-
public class Program
{
public static void main(String[] args) {
int i,j;
String W="hello";
for(i=0;i<=W.length();i++)
{
for(j=0;j<i;j++){
System.out.print(W.charAt(j));
}
System.out.println();
}
}
}
By the way Thankyou everyone for answering and helping me out.
+ 1
Michal Thank you for the answer
+ 1
🅰🅹 - ɪ'ᴍ ᴄʀɪᴍɪɴᴀʟʟʏ ɢᴏᴏᴅ!, "Methods or library not allowed..."
You guys both used methods from String class so what is the difference?
+ 1
Michal I deleted my answer.😂😂