Question: Please do some chenge on this code that can make it auto fill in random integers after input a size of array, then output the

Please do some chenge on this code that can make it auto fill in random integers after input a size of array, then output the both unsorted order and ascending order

import java.util.Scanner;

public class sort {

public static void main(String[] args)

{

int n, temp;

Scanner s = new Scanner(System.in);

System.out.print("Enter no. of elements you want in array:");

n = s.nextInt();

int a[] = new int[n];

System.out.println("Enter all the elements:");

for (int i = 0; i < n; i++)

{

a[i] = s.nextInt();

}

for (int i = 0; i < n; i++)

{

for (int j = i + 1; j < n; j++)

{

if (a[i] > a[j])

{

temp = a[i];

a[i] = a[j];

a[j] = temp;

}

}

}

System.out.print("Ascending Order:");

for (int i = 0; i < n - 1; i++)

{

System.out.print(a[i] + ",");

}

System.out.print(a[n - 1]);

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!