Processing a string from the console
Yeah, without giving too much away (this is obviously homework)....

First though, the assumption I make is that the assignment is:


find the length of the longest series of either increasing, or decreasing numbers
sum the values in this longest sequence.


There are two parts to this problem as well. The first part is getting the user input, and the second is identifying and processing the sequences. I will assume that you can process the user input adequately, and put it in an array of integer int[] values = .... You use an ArrayList&lt;Integer&gt; which is not, in my opinion, a great container for doing arithmetic on...

This problem can be solved by managing three variables, and keeping a maxlen and maxsum total.

First you need to ensure you have at least 2 items in your values array, and, assuming you do, you initialize your three variables:

boolean increasing = values[0] &lt; values[1];
int sum = values[0];
int len = 1;

int maxlen = len;
int maxsum = sum;


OK, we set up the system where we expect the third value to be a continuation of the sequence.... and then we start the loop, starting from position 1 (the second item) in the values array:

for (int i = 1; i &lt;= arrays.length; i++) {
    // check here to see if we are going in the same direction
    if ( (increasing &amp;&amp; value[i] &gt;= value[i -1]) || ( ...decreasing and next is smaller) ) {
        // we are going on in the same direction as before:
        // increase the length, and add value[i] to the sum.
        // if the length is larger than maxlen, then change maxlen and maxsum to len and sum
    } else {
        // the value at position i breaks the sequence.
        // reset len and sum to be 2 and the sum of this and the previous value

        // EDIT: 'Obviously' you record the change in direction!
        increasing = !increasing;

    }
}

System.out.printf("The longest sequence is %d values long, and has a sum of %d\n", maxlen, maxsum);


Without going in to too much detail, you can easily convert this algorithm to work at the same time as you process the user input.... there is no real reason why you have to first convert all the values to int first, and only then process them.... you can process them as they are entered.

EDIT: I realize you may need to be smarter than I have suggested when setting up the variables initially... if the first values in the input are all the same then the algorithm above will assume the sequence is not increasing and will produce the wrong result. You need to find out the initial 'direction' of the sequence by looking for the first 'different' value