import java.util.*;
class RandomNumbers
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the size of the array");
int size=s.nextInt();
int a[]= new int[size];
Random tr= new Random();
for (int i = 0;i < size;i++)
{
a[i]=tr.nextInt(100);
}
System.out.println("Unsorted Array");
for(int i = 0;i < size;i++)
System.out.println(a[i]);
for (int i = 0;i < size;i++)
{
for(int j = i+1;j < size; j++)
{
if (a[i] > a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println("Sorted Array");
for(int i = 0;i < size;i++)
System.out.println(a[i]);
}
}
class RandomNumbers
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter the size of the array");
int size=s.nextInt();
int a[]= new int[size];
Random tr= new Random();
for (int i = 0;i < size;i++)
{
a[i]=tr.nextInt(100);
}
System.out.println("Unsorted Array");
for(int i = 0;i < size;i++)
System.out.println(a[i]);
for (int i = 0;i < size;i++)
{
for(int j = i+1;j < size; j++)
{
if (a[i] > a[j])
{
int temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
System.out.println("Sorted Array");
for(int i = 0;i < size;i++)
System.out.println(a[i]);
}
}
SAMPLE OUTPUT:
No comments:
Post a Comment