+ 1

How to output 1 22 333 22 1with the input of 123 using java send help

How to output 1 22 333 22 1with the input of 123 using java send help

19th Jul 2020, 3:42 PM
Martin
Martin - avatar
21 Respuestas
+ 3
Pls share your attempt
19th Jul 2020, 3:46 PM
Nilesh
Nilesh - avatar
+ 2
Show me what you tried, I don't make promises, but if you try, then I will try to help you get through. Save the code in SoloLearn and share its link in your thread Description. Follow the below guide in case you don't know how. Good luck! 👍 https://www.sololearn.com/post/75089/?ref=app
19th Jul 2020, 3:54 PM
Ipang
+ 2
Martin I finally got it done But for this I take the input using a String instead of number. https://code.sololearn.com/cAWRDN8QBwaM/?ref=app
19th Jul 2020, 5:48 PM
Ipang
+ 2
I was referring to your original question where all the characters are printed on the same line. But if you prefer to print on different lines then you can replace line 29 from this ... System.out.print(" "); Into this ... System.out.println(); Pretty simple 👌
20th Jul 2020, 9:02 AM
Ipang
+ 1
import java.util.Scanner; public class Example { public Example() { } public static void main(String args[]) { Scanner input = new Scanner(System.in); int n; n = input.nextInt(); for(int i=1; i<=n; i++){ for (int j=0;j<i;j++) System.out.print(i); System.out.println(); } for(int i=n-1; i>0; i--){ for(int j=0; j<i; j++) System.out.print(i); System.out.println() ; } }
19th Jul 2020, 4:05 PM
Martin
Martin - avatar
0
That is my code. When I input 3 i come with the output of 1 22 333 22 1 but I need to input 123 and get the same output. Send help
19th Jul 2020, 4:06 PM
Martin
Martin - avatar
0
Martin How it should be if we got a number with even number of digits? e.g. 1234. 1 22 333 4444 333 22 1 Is above correct for output?
19th Jul 2020, 4:25 PM
Ipang
0
Yes the output is correct if you have to input 1234.
19th Jul 2020, 4:28 PM
Martin
Martin - avatar
0
Martin Is it also okay if we turn the number into a,string? I just have an idea using string ...
19th Jul 2020, 4:29 PM
Ipang
0
Yes its okay but I also need to input character. For example, QWE the output should be Q WW EEE WW Q
19th Jul 2020, 4:32 PM
Martin
Martin - avatar
0
Okay I get it, so it accepts string too. I'll get back later I hope someone can come up with something sooner though ...
19th Jul 2020, 4:34 PM
Ipang
0
Okaay thank you so much. I appreciated your effort, I'll just wait you after your code is done.
19th Jul 2020, 4:36 PM
Martin
Martin - avatar
0
How to make this output 1 22 333 22 1 instead of this 1 22 333 22 1?
20th Jul 2020, 3:14 AM
Martin
Martin - avatar
0
But how if I input in different lines? like 1 2 3
21st Jul 2020, 6:09 AM
Martin
Martin - avatar
0
That would mean 3 inputs (1, 2 and 3) instead of just 1 input (123). The Scanner reads a line, if you want, you can put the code into a loop so multiple input can be supported.
21st Jul 2020, 6:13 AM
Ipang
0
Yes but how to put the code into the loop. I'm trying to understand the code first.
21st Jul 2020, 6:17 AM
Martin
Martin - avatar
0
Ping me when you made the code into a loop, or maybe a method. I'd like to see it 👌
21st Jul 2020, 6:19 AM
Ipang
0
But how to do that? can you help me? I'm still trying to understand the code
21st Jul 2020, 6:21 AM
Martin
Martin - avatar
0
It's okay, no need to rush. Did I over complicated the code? Anyways, I think you can do it 👍
21st Jul 2020, 6:23 AM
Ipang
0
Can you help me how to made the code into loop?
21st Jul 2020, 6:25 AM
Martin
Martin - avatar