It does no good to supply a ready‑made answer. Don't be annoyed, but I have pulled rank and removed the solution.We're all here to learn, so when responding to others, please focus on helping them discover their own solutions, instead of simply providing answers.
Could you please repost this and enclose it in "Code" tags so that we can see the exact format that you are looking for. And one for "768" also.sai rama krishna wrote:i want instead output something like pyramid as below with proper spaces at the beginning and at the end when i enter any given number like 123456 or 123 or 786 and also i need those numbers to be sorted alos
Please enter number:
123456
1
22
333
4444
55555
666666
You could try something like this
?
1
throw new IfCampbellSeeThisHellDeleteItException();
sai rama krishna wrote:but some of the comments are not at all friendly esp. above comment by Sankalp.
The problem with the pyramid as shown in your screen shot is that the position of digits in alternate rows are shifted by have a character width, which is impossible.
You could do this if there was a space between each digit, otherwise we'd need a screen shot of what would be expected for this odd/even row problem without moving a line by half a character width.
sai rama krishna wrote:i am fine having a space between each digit. How to achieve that? please advise
Carey Brown wrote:The problem with the pyramid as shown in your screen shot is that the position of digits in alternate rows are shifted by half a character width, which is impossible.
Now, starting at line 6, how many leading spaces do you need? Line 5?, Line 4? See a pattern forming?
Line 37 needs to be print() not println().sai rama krishna wrote:
sai rama krishna wrote:here spaces seems tricky where at line one it has number_of_digits/2 and then keep on reducing as we go down i think?
sai rama krishna wrote:
you mean like above add space beore printing the number in the for loop?
i got below wrong output
Please enter number:
126
1
2
2
6
6
6
Spacing between the lines can be arguable.
Anyways, see the difference between print() and println() methods. You are printing both spaces and digits so you have to adjust your code according to your need with perticular spaces in between
sai rama krishna wrote:
above gave below output but trailing spaces are not coming correct
Please enter number:
124
1
2 2
4 4 4
please advise
sai rama krishna wrote:please advise
HIGH LEVEL: Print a triangle from numbers entered by the user
NEXT LEVEL:
Given a String entered by the user,
Split the String up into an array that has 1 element per character in the String
Print each character as a line in the pyramid.
NEXT LEVEL: (print each character as a line in a the pyramid)
Print leading spaces
Print the character
Print a linefeed
NEXT LEVEL:
print leading space before a character
print the characters in the incremental order each line like 1 time in first line and 2 times in 2nd line and 3 times in 3rd line etc
NEXT LEVEL:
Given a String entered by the user,
Split the String up into an array that has 1 element per character in the String
Print each character as a line in the pyramid.
Politics n. Poly "many" + ticks "blood sucking insects". Tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|