Write a program in Java to accept a no. And arrange the digits in ascending order
Answers
Answered by
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
India Languages,
7 months ago
Business Studies,
7 months ago
Math,
7 months ago
Political Science,
1 year ago
Science,
1 year ago
Chemistry,
1 year ago