I am trying to make a simple Java program where you input 15 numbers (INTS, positive and negative) first, let's say these will get loaded into arrayOne. After that all numbers that are below '-5' need to be loaded into a second array (arrayTwo). I want to print all numbers of arrayTwo, while still retaining all arrayOne numbers.
I know my code doesn't make any sense at all, as I am still a beginner (about a month on and off). This is my code so far:
import java.util.Scanner;
public class Main {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
int[] arrayOne = new int[15];
int count = 0;
System.out.println("Input 15 ints: ");
for (int i = 0; i <= arrayOne.length-1; i++){
arrayOne[i] = scanner.nextInt();
if (arrayOne[i] < -5){
count++;
}
}
int[] arrayTwo = new int[count];
for (int i = 0; i <= arrayOne.length-1; i++){
if (arrayOne[i] < -5){
arrayOne[i] = arrayTwo[i];
}
}
}
}
It's so confusing for me. I don't know what to do to be honest. Do I need to use some kind of nested loop?
Thank you so much in advance, any help will be greatly appreciated.