info@meritcampus.com    +91-85006-22255
...
`

### Intermediate Level Test 7 has these questions

Sort Array Ascending Order

Write a program to sort the input array in ascending order.
Input (Integer Array) Output (Integer Array)
`{2, 3, 4, 7, 6, 1}` `{1, 2, 3, 4, 6, 7}`
`{3, 9, 1, 5, 16, 10}` `{1, 3, 5, 9, 10, 16}`
``` class SortArrayElements {    public static void main(String s[])    {        int[] input = {4, 6, 19, 2, 7, 12, 1, 9};        sortArray(input);        System.out.print("Elements after sorting are : ");        for(int element : input)        {            System.out.print(element + ", ");        }    } public static void sortArray(int[] input) { //Write code here to sort the input array } } ```

Create Array Copy

Write a program to create a copy of the input array.
Input (Integer Array) Output (Integer Array)
`{2, 3, 4, 7, 6, 1}` `{2, 3, 4, 7, 6, 1}`
`{3, 9, 1, 5, 16, 10}` `{3, 9, 1, 5, 16, 10}`
``` class CopyArray {    public static void main(String s[])    {        int[] input = {4, 6, 19, 2, 7, 12, 1, 9};        int[] copy = copyArray(input);        System.out.print("The copy of the array is : ");        for(int element : copy)        {            System.out.print(element + ", ");        }    } public static int[] copyArray(int[] input) { int[] output = null; //Write code here to copy input array to output array return output; } } ```

Sum of 3 consecutive numbers in the input array

Write a program to sum of consecutive 3 numbers in the input array.
NOTE: The input array size may NOT be a perfect multiple of 3.
Input (Integer Array) Output (Integer Array)
`{2, 3, 4, 7, 6, 1}` `{(2 + 3 + 4), (7 + 6 + 1)} = {9, 14}`
`{3, 9, 1, 5, 16, 10, 4}` `{(3 + 9 + 1), (5 + 16 + 10), (4)} = {13, 31, 4}`
`{3, 9, 1, 5, 16, 10, 4, -6}` `{(3 + 9 + 1), (5 + 16 + 10), (4 + -6)} = {13, 31, -2}`
``` class SumOfThreeConsecutiveNumbersInArray {    public static void main(String s[])    {        int[] input = {2, 6, 3, 8, 1};        int[] output = sumOfThreeConsecutiveNumbers(input);        System.out.print("Output array is : ");        for(int i = 0; i < output.length; i++)        {            System.out.print(output[i] + ", ");        }    } public static int[] sumOfThreeConsecutiveNumbers(int[] input) { int[] output = null; //Write code here to sum of consecutive 3 numbers in input array and assign it to output return output; } } ```

Print Prime Numbers In Given Range

Write a program to print the prime numbers in the given range. Spaces between numbers are important and all the numbers should be in the same line. Use System.out.println or System.out.print for printing.
Input (Integer, Integer) Printed Output
`1, 10` `2 3 5 7`
`10, 20` `11 13 17 19`
``` class PrintPrimeNumbers {    public static void main(String s[])    {        printPrimeNumbers(30,40);    } public static void printPrimeNumbers(int startValue, int endValue) { //Write code here to print the prime numbers between the startValue and endValue. Use System.out.println or System.out.print for printing. } } ```

Copy odd numbers into another array

Write a program to copy the odd numbers into another array.
Input (Integer Array) Output (Integer Array)
`{2, 3, 4, 6, 7, 1}` `{3, 7, 1}`
`{3, 9, 1, 16, 5, 10}` `{3, 9, 1, 5}`
``` class CopyOddNumbersInArray {    public static void main(String s[])    {        int[] input = {2, 6, 3, 8, 1};        int[] output = copyOddNumbers(input);        System.out.print("Odd Numbers in the array are : ");        for(int i = 0; i < output.length; i++)        {            System.out.print(output[i] + ", ");        }    } public static int[] copyOddNumbers(int[] input) { int[] output = null; //Write code here to copy the odd numbers in input array and assign it to output return output; } } ```