Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

import java.util.

*;
class Bubblesort
{
public static void main (String args [] )
{
int i,j;
int temp;
System.out.println ("How many nos. do you want to enter?");
Scanner sc = new Scanner(System.in);
int sz=sc.nextInt();
int num[]=new int[sz];
for(i=0;i<sz;i++)
{
num[i]=sc.nextInt();
}
System.out.println("Before sort The numbers are");
for(i=0;i<sz;i++)
{
System.out.print(num[i]+" ");
}
System.out.println("After sort The names are");
for(i=0;i<sz;i++)
{
for(j=0;j<sz-i-1;j++)
{
if(num[j]>num[j+1])
{
temp=num[j];
num[j]=num[j+1];
num[j+1]=temp;
}
}
}
System.out.println("\nAfter sort The names are");
for(i=0;i<sz;i++)
{
System.out.print(num[i]+" ");
}
}
}

You might also like