Write a program that gets a list of integers from input, and outputs the integers in ascending order (lowest to highest). The first integer indicates how many numbers are in the list. Assume that the list will always contain less than 20 integers. Ex: If the input is: 5 10 4 39 12 2 the output is: 2 4 10 12 39 For coding simplicity, follow every output value by a space, including the last one. Your program must define and call the following function. When the SortArray function is complete, the vector passed in as the parameter should be sorted. void SortVector(vector& myVec) Hint: There are many ways to sort a vector. You are welcome to look up and use any existing algorithm. Some believe the simplest to code

Respuesta :

Answer:

See explaination

Explanation:

// import the necessary package.

import java.util.Scanner;

// declare a class.

public class Labprogram {

// Start the main

public static void main(String[] args) {

// declare the input of scanner class.

Scanner input = new Scanner(System.in);

// input number.

int numb = input.nextInt();

// declare an array.

int[] in_arr = new int[numb];

// start the for loop

for (int b = 0; b < in_arr.length; b++) {

// Assign values to array.

in_arr[b] = input.nextInt();

}

// Call the method.

SortArray(in_arr, numb);

input.close();

}

// Definition of the method.

private static void SortArray(int[] myArr, int arrSize) {

// Declare an array.

int[] S_Array = new int[arrSize];

int temp;

// start the for loop

for (int j = 0; j < myArr.length - 1; j++) {

// start the for loop

for (int i = 0; i < myArr.length - 1; i++) {

// check the condition.

if (myArr[i] > myArr[i + 1]) {

// swap the values.

temp = myArr[i];

myArr[i] = myArr[i + 1];

myArr[i + 1] = temp;

S_Array = myArr;

}

}

}

// declare the object of set builder class.

StringBuilder build = new StringBuilder();

// start the for loop

for (int val : S_Array) {

build.append(val + " ");

}

// Declare variable.

String numb = build.toString();

// Assign value.

System.out.println(numb);

}

}