This is the instruction in one of the exercises in our Java class. Before anything else, I would like to say that I \'do my homework\' and I\'m not just being lazy asking someon
class Sort
{
public static void main(String[] args)
{
System.out.println("Enter the range");
java.util.Scanner sc=new java.util.Scanner(System.in);
int n=sc.nextInt();
int arr[]=new int[n];
System.out.println("Enter the array values");
for(int i=0;i<=n-1;i++)
{
arr[i]=sc.nextInt();
}
System.out.println("Before sorting array values are");
for(int i=0;i<=n-1;i++)
{
System.out.println(arr[i]);
}
System.out.println();
for(int pass=1;pass<=n;pass++)
{
for(int i=0;i<=n-1;i++)
{
if(i==n-1)
{
break;
}
int temp;
if(arr[i]>arr[i+1])
{
temp=arr[i];
arr[i]=arr[i+1];
arr[i+1]=temp;
}
}
}
System.out.println("After sorting array values are");
for(int i=0;i<=n-1;i++)
{
System.out.println(arr[i]);
}
}
}