Trace through the code and figure out where the 1 come from. Then figure out how it got there.
Printable View
Trace through the code and figure out where the 1 come from. Then figure out how it got there.
Hi. This where I'm at right now.
The error comes when I test for sequence 1 3 3 5 4 2 3
Code Java:
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;
I did the trace. It's solved. With an if loop at the bottom.