Exercise Beginner: Sort array(Bubble sort)
Request: Write a program that inputs n natural numbers and a natural number k. Sort the input by non-descending order and then insert element k in such a way that the new resulted array is also sorted (1 ≤ n ≤ 1000, 1 ≤ numbers, k ≤ 1000000). Solution In order to be able to solve this exercise the programmer must know the concept of array which we have seen on lesson 8 , if condition which we have seen on lesson 4 and the for loop which we have seen on lesson 7 . So from the request we see that we must get from the user the k number. We can do this operation through the given code bellow: Example code: System.out.println("Gvie the k element:"); int k = scannInt.nextInt(); Where scannInt is an instance of Scanner class which is shipped within JDK and is found inside the java.util package, so in order to use it we need to add the line bellow in the beginning of the application if our class is not inside any package or directly bellow the package if the ...