Computer Science, asked by Olivia15, 1 year ago

write a program in "Java" to arrange the array element in ascending order
In two ways:

a).By selective sorting
b). By bubble sorting.


Please don't spam! tommorow is my exam!

Answers

Answered by nancyyy
12
Hey!
Here is the answer:
======================================

 \boxed{Using Selective Sorting:}

import java.util.*;

Class Selective_sort
{
public static void main (String args [ ])
{
Scanner sc=new Scanner (System.in);

int a[ ]= new int [10];
int t=0, min=0;

System.out.println ("Enter your array elements in unsorted order");

for(int i=0; i<10 ; i++)
{
a[i]= sc.nextInt( );
}
for(int i=0; i<9 ; i++)
{
min=i;
for(int j=i+1; j<10 ; j++)
{
if(a[j] < a[min])
{
if(a[j] < a[min])
{
min=j;
}}
t= a[min];
a[min]= a[i];
a[i]=t;
}
System.out.println("After sorting the array elements are:");
for(int i= 0; i<10; i++)
{
System.out.println(a[i]);
}}}
_________________________________


 \boxed{Using Bubble Sorting:}

import java.util.*;

Class Selective_sort
{
public static void main (String args [ ])
{
Scanner sc=new Scanner (System.in);

int a[ ]= new int [10];
int t=0;
System.out.println("Enter the array elements in unsorted order:");

for (int i=0; i<10; i++)
{
a[i]= sc.nextInt( );
for(int i=0; i<10; i++)
{
for(int j=0; j<10-i-1; j++)
{
if(a[j]< a[j+1])
{
t= a[j];
a[j+1]= a[j];
a[j+1]=t;
}
}
System.out.println("After Sorting:");
for(int i=0; i<10; i++)
{
System.out.println(a[i]);
}
}
}


Olivia15: Thanku so muchhhh
nancyyy: you're welcome ^^
DaIncredible: woah :O
DaIncredible: Awesome answer nanno
nancyyy: thanka :p
Anonymous: Woooooaaaahhhh!
Anonymous: Kuch bhi nahi ghusa XD
Similar questions