Whenever I run the code it prints out the second half of the 20 numbers I entered and I'm sure that it copies the first half of them to the first smaller array. So I can't understand why I'm not reaching a few of the conditions. I wanted to do this problem a few different ways so that I just have a better grasp of how to manipulate arrays. But I'm having a lot of trouble with this part right now.
package com.codegym.task.task07.task0705;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.nio.Buffer;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
/*
One large array and two small ones
1. Create an array of 20 numbers.
2. Populate it with values from the keyboard.
3. Create two arrays of 10 numbers each.
4. Copy the large array into the two small ones: half the numbers
into the first small array, and the second half into the second small array.
5. Display the second small array, each value on a new line.
Requirements:
1. The program must create an array of 20 integers.
2. The program should read 20 numbers from the keyboard for the large array.
3. The program must create two small arrays of 10 numbers each.
4. The program must copy one half of the large array into the first small
array, copy the second half into the second array, and then display that array on the screen.
*/
public class Solution {
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
Integer[] twenty = new Integer[20];
Integer[] zerotoNine = new Integer[10];
Integer[] tentoTwenty = new Integer[10];
for (int i = 0; i < 20; i++)
twenty[i] = Integer.parseInt(br.readLine());
for (int i = 0; i < 10; i++)
zerotoNine[i] = twenty[i];
Arrays.sort(twenty, Collections.reverseOrder());
for (int i = 0; i < 10; i++) {
tentoTwenty[i] = twenty[i];
}
Arrays.sort(tentoTwenty, Collections.reverseOrder());
for (int i = 0; i < 10; i++)
System.out.println(tentoTwenty[i]);
}
}