write a program in java to input a number and arrange its digit in ascending order
Answers
Answer:
import java.util.Scanner;
public class KboatDigitSort
{
public void sortDigits() {
Scanner in = new Scanner(System.in);
System.out.print("Enter a number having 3 or more digits: ");
int OrgNum = in.nextInt();
for (int i = 0; i <= 9; i++) {
int num = OrgNum;
int c = 0;
while (num != 0) {
if (num % 10 == i)
c++;
num /= 10;
}
for (int j = 1; j <= c; j++) {
System.out.print(i + ", ");
}
}
System.out.println();
}
}
Explanation:
//Program to arrange digits in ascending order
import java.util.*;
class abc{
public static void main (String ar[]){
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int N1=0,N2=n;
for(int I=0;I<=9;I++){
while(n!=0){
if(n%10==I)
N1=N1*10+(n%10);
n/=10;
}
n=N2;
}
System.out.println("New number:"+N1);
}
}
Similar Question Previously Asked:
https://brainly.in/question/42233483