+ 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
21 odpowiedzi
+ 3
Pls share your attempt
+ 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
+ 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
+ 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 👌
+ 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() ;
}
}
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
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?
0
Yes the output is correct if you have to input 1234.
0
Martin
Is it also okay if we turn the number into a,string? I just have an idea using string ...
0
Yes its okay but I also need to input character. For example, QWE the output should be Q WW EEE WW Q
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 ...
0
Okaay thank you so much. I appreciated your effort, I'll just wait you after your code is done.
0
How to make this output
1
22
333
22
1
instead of this 1 22 333 22 1?
0
But how if I input in different lines? like
1
2
3
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.
0
Yes but how to put the code into the loop. I'm trying to understand the code first.
0
Ping me when you made the code into a loop, or maybe a method. I'd like to see it 👌
0
But how to do that? can you help me? I'm still trying to understand the code
0
It's okay, no need to rush.
Did I over complicated the code?
Anyways, I think you can do it 👍
0
Can you help me how to made the code into loop?