+ 3

Please help, any idea?

https://www.sololearn.com/post/1724283/?ref=app Can someone give me some help how this loop should join with inside pattern ? https://code.sololearn.com/cm4q67n0vXgK/?ref=app

1st Feb 2023, 3:09 PM
Sakshi [Offline šŸ™ƒ]
Sakshi [Offline šŸ™ƒ] - avatar
5 Answers
+ 3
Ok, I try it. Thanks Sir.
1st Feb 2023, 5:10 PM
Sakshi [Offline šŸ™ƒ]
Sakshi [Offline šŸ™ƒ] - avatar
+ 2
You can try like this : Replace line 8,9 by these : System.out.println(" ā€¢ ā€¢ " +" ".repeat(11)+" ā€¢ "+" ".repeat(10)+" ā€¢ ā€¢"); System.out.println(" ā€¢ ā€¢ " +" ".repeat(10)+"ā€¢ ā€¢"+" ".repeat(9)+" ā€¢ ā€¢"); edit: Sakshi but this approach is hard coding is not good way.. instead your program work for any input number of lines of code. try this way : for repeating String you can store in variables. you are just printing a sequential pattern si use a loop like for( int i = 11 , j = 1 ; i > 5; i--, j++ ) { System.out.println(" ā€¢ ā€¢ " +" ".repeat(i)+" ā€¢ "+"\t".repeat(j)+" ā€¢ "+" ".repeat(i-1)+" ā€¢ ā€¢"); } this sample, reduce a 10 lines of code to just 3 lines... j value for repeating tab space between. there is little bit changes needed. hope you try and find it. (Am not checked. If anything not work, you can reply..)
1st Feb 2023, 3:47 PM
Jayakrishna šŸ‡®šŸ‡³
+ 2
I try it also, but is there any method i can join inside pattern in Java? Thanks Sir btw
1st Feb 2023, 4:27 PM
Sakshi [Offline šŸ™ƒ]
Sakshi [Offline šŸ™ƒ] - avatar
+ 2
Join methods available but there it is not joining string happening... It is like merging. And it is possible with gui but not with console based. It needed actually like to make a decorator. First 2 lines and last 2 lines are same so make a function to print 2 lines or like a string print as System.out.println( " ā€¢ ā€¢".repeat(12) +"\n"+" ā€¢ ā€¢".repeat(12)) ; Add above mention loop. And again add print. Instead of printing, you can store in string and print or repeat it again..
1st Feb 2023, 4:42 PM
Jayakrishna šŸ‡®šŸ‡³
+ 2
I guess this is not possible since the compiler works from top to bottom and from left to right. You need to write the entire line. https://code.sololearn.com/c7m7aWFgC8A6/?ref=app
1st Feb 2023, 6:33 PM
Solo
Solo - avatar