Question: I'm trying to get the code to `break` when the `int` receives a negative number.

Here is my code:

```
package merge.arrays;

import java.util.ArrayList;
import java.util.Scanner;

public class MergeArrays {
    public static void main(String[] args) {
        ArrayList<String> list = new ArrayList<>();
        Scanner input = new Scanner(System.in);

        System.out.println("Enter the value for the 1st array (0-10000), and enter a negative number to quit:");
        int array1 = input.nextInt();
        while (array1 >= -1) {
            for (int i = 0; i < 10000; i++) {
                array1 = array1 + input.nextInt();
                if (array1 <= -1) {
                    break;
                }
            }
        }

        System.out.println("Enter the value for the 2nd array (0-10000), and enter a negative number to quit:");
        int array2 = input.nextInt();
        while (array2 >= -1) {
            for (int i = 0; i < 10000; i++) {
                array2 = array2 + input.nextInt();
                if (array2 <= -1) {
                    break;
                }
            }
        }

        System.out.println("1st array:\n" + array1);
        System.out.println("2nd arrat:\n" + array2);
    }
}

```

Answer: 
Looking at your question there are some issues as follow: 

1. I don't know what is the purpose of ArrayList list because you are not using it anywhere
2. Your questions mentions about arrays int[] but, you are not using arrays at all
3. You are asking for user input and then in the while loop you are saying `while (array1 >= -1)` which contradicts the purpose of your question that you want to break when negative value is provided
4. Assuming that your first input was not negative, inside the loop you are adding the value of the input as you get it from user and then check if it is negative or positive rather than first checking the input then adding it to the previous value

Reading your question, I understand that you want to stop asking user for input when you detect that input was negative value. If that is the purpose then you need the following modifications in your code: 

```
while (array1 >= 0){
    for(int i = 0; i < 10000; i++){
        //get user input in temp
        int temp = input.nextInt(); 

        if(temp < 0) {
            //user provided negative value, so break from loop
          break;
        } else {
          array1 = array1 + temp;
        }
    }
}

```

Make the above change to the both while loops and you should be all good.
Your code :

```
    int array1;
    array1 = input.nextInt();

    while (array1 >= -1)   // why this outer loop 
    {
        for(int i = 0; i < 10000; i++) {
            array1 = array1 + input.nextInt();  //You are adding previous values with new values, how it will determine if entered a negative number.
            if(array1 <= -1) {
                break;
            }
        }
    }

```

For example:
Let I entered 4 5 -1 6
First time array1 = 4, while loop true so go inside loop, then upto 10000 time you are adding value so lets suppose it added 4+5=9 and third time `array2=array2+(-1)` which is 8 and if() condition is false, for loop is executed one more time. Error !!!!!

So you have to use something like this:

```
int array1;
for(int I=0;i<10000;i++)
{
   int temp = input.nextInt();
   if(temp < 0)
   {
     break;
   }
   array1 = array1+temp;
}

```