Computer Science, asked by harsha116, 1 year ago

Write a program in Java to accept a no. And arrange the digits in ascending order

Answers

Answered by amanpeekay0
3

Hey Mate!


Here's the answer :-

import java.io.* ;

class Work

{

int a[] = new int[10] ;

int tmp;

void sort()

{

for(int i = 0; i < 10; i++)

{

System.out.println("Enter the numbers.")

a[i] = Integer.parseInt(br.readLine())

}

for(int i = 0; i <10 ; i++)

{

for(int j = 0; j<(10-i); j++)

{

if( a[ j ] > a[ j + 1 ] )

{

tmp = a[ j ] ;

a[ j ] = a[ j + 1 ] ;

a[ j +1 ] = tmp ;

}

}

}

System.out.println("The Sorted Array is :") ;

for(int  i = 0; i < 10; i++)

{

System.out.println( a[i] ) ;

}

}




Hope it helps!

Similar questions