Write a java program to input 20 integer elements in an array and sort them in descending
order using bubble sort technic.
Answers
Answered by
8
Verification Answer✔️ :
import java.util.Scanner ;
class sorting
{
p.s.v.m ()
{
Scanner sc = new Scanner ( System.in);
int i , j , t = 0;
S.o.pln ( "enter 20 no.");
int a [ ] = new int [20]
for (i=0;i<=19 ;i++)
{
a[ i ] = sc.nextint( ) ;
}
for (i=0;i<=18;i++)
{
for ( j=0;j<=18;j++)
{
if (a[j] < a[ j+i] )
{
t=a[j] ;
a[j ] = a [j+1] ;
a[j+1] = t ;
}
}
}
S.o.pln ( "descending order ");
for (i = 0 ; i<=19 ; i++)
{
S.o.pln ( a[i] ) ;
}
} [closing of function]
} [ closing of class ]
Similar questions