Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Find the the longest decreasing row of numbers in a vector

1. ## Re: Find the the longest decreasing row of numbers in a vector

Trace through the code and figure out where the 1 come from. Then figure out how it got there.

2. ## The Following User Says Thank You to jps For This Useful Post:

einar123 (September 24th, 2013)

3. ## Re: Find the the longest decreasing row of numbers in a vector

Hi. This where I'm at right now.

The error comes when I test for sequence 1 3 3 5 4 2 3

```
package forrit;

public class Verkefni2tplus {

public static void main(String[] args) {
int N = args.length;
int[] a = new int[N];
int downcounter=1;
int upcounter=1;
int goodolddowncounter=1;
for (int i = 0;i<N;i++) {
a[i] = Integer.parseInt(args[i]);
}

{
for(int i=0;i<N-1;i++)

if (a[i]>=a[i+1])
{
downcounter++;
goodolddowncounter=downcounter;
}
else
{
upcounter++;
}
}
if (upcounter>downcounter)
{
goodolddowncounter=downcounter;
downcounter=1;
}

System.out.print(goodolddowncounter);
}
}```

--- Update ---

int goodolddowncounter=0;

4. ## Re: Find the the longest decreasing row of numbers in a vector

I did the trace. It's solved. With an if loop at the bottom.

Page 2 of 2 First 12