acending pyramid of numbers

on
hi,
let us say i give some random number like 81349 on console i should see output as by ascending order of each digit in each line how to achieve that as well

1
3 3
4 4 4
8 8 8 8
9 9 9 9 9

how to to achive this
Comment
Watch Question

Do more with

EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Database Expert
Awarded 2016
Top Expert 2016

Commented:
First get the number in an Int array , Sort it and provide each number to the program instead of *.

NoOfRows  = Array Count.

System.out.print("* "); --> Instead o this provide the number

You can print the pyramid using this code-

``````int NoOfRows = 5, k = 0;

for(int i = 1; i <= NoOfRows; ++i, k = 0) {
for(int space = 1; space <= NoOfRows - i; ++space) {
System.out.print("  ");
}

while(k != 2 * i - 1) {
System.out.print("* ");
++k;
}

System.out.println();
``````

https://www.programiz.com/java-programming/examples/pyramid-pattern
Quid, Me Anxius Sum?  Illegitimi non carborundum.

Commented:
I'd do it this way

Turn number into an array of bytes, one digit into each byte.
You can then determine the number of bytes you have.
Use a for loop to find the lowest number and then process that.  (for 1 to maximum no of bytes)
Repeat for the next lowest number and then process that.
Repeat until finished.

Note that you may have to consider cases where you have duplicate numbers such as 232456 (the 2s are duplicated twice).
Also what happens if you have a 0 in the number?
Top Expert 2016

Commented:
Database Expert
Awarded 2016
Top Expert 2016
Commented:
Here 's final solution for you. FULL tested code.

``````//'main' method must be in a class 'Rextester'.
//Compiler version 1.8.0_111

import java.util.*;
import java.lang.*;
import java.util.Arrays;

class Rextester
{
public static void main(String args[])
{
int num = 81349;
int[]digits = Integer.toString(num).chars().map(c -> c-='0').toArray();
Arrays.sort(digits);
int n = Integer.toString(num).length();
int k = 2*n - 2;

for (int i=0; i<n; i++)
{

for (int j=0; j<k; j++)
{

System.out.print(" ");
}
k = k - 1;
for (int j=0; j<=i; j++ )
{
System.out.print(digits[i] + " ");
}

System.out.println();
}
}
}
``````

Output

``````        1
3 3
4 4 4
8 8 8 8
9 9 9 9 9
``````

Enjoy !!
Top Expert 2016

Commented:
Here 's final solution for you. FULL tested code.
We don't give OPs full code here. Try to think why
Database Expert
Awarded 2016
Top Expert 2016

Commented:
We don't give OPs full code here. Try to think why

I below case I have not given OPs the full code. I asked him to add a where clause. You can see my solution was selected and solutions based on my suggestion was selected as answer.

Top Expert 2016

Commented:
Sorry - i don't understand the connection between this question and the one you linked to

Commented:
We don't give OPs full code here. Try to think why

Reason being . . . it is far easier to get someone else to do it. That avoids having to learn anything yourself, which as we all know is an unneeded luxury.
Senior Consultant
Awarded 2017
Distinguished Expert 2018

Commented:
Reason being . . . it is far easier to get someone else to do it. That avoids having to learn anything yourself, which as we all know is an unneeded luxury.
We don't give OPs full code here. Try to think why
Then apply this reasoning to everyone, not just ones that resembled homework. It is up to the experts whether they want to answer these, EE policy around this has changed.

Do more with