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


Members have full access to the forums. Advertisements are removed for registered users.

Page 2 of 2 FirstFirst 12
Results 26 to 28 of 28

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

  1. #26
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 262 Times in 231 Posts

    Default 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. #27
    Member
    Join Date
    Aug 2013
    Location
    Reykjavik, Iceland
    Posts
    51
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default 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. #28
    Member
    Join Date
    Aug 2013
    Location
    Reykjavik, Iceland
    Posts
    51
    Thanks
    37
    Thanked 0 Times in 0 Posts

    Default 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 FirstFirst 12

Similar Threads

  1. Why width of dropdown is decreasing automatically on every select?
    By ayush1989 in forum Other Programming Languages
    Replies: 0
    Last Post: February 1st, 2013, 12:39 AM
  2. Binary Tree Longest Increasing Path (Recursive)
    By varsis in forum Algorithms & Recursion
    Replies: 0
    Last Post: April 13th, 2012, 10:19 PM
  3. [SOLVED] Display longest string on screen
    By mwardjava92 in forum Object Oriented Programming
    Replies: 1
    Last Post: January 29th, 2012, 11:12 AM
  4. Increasing or decreasing!
    By pesha in forum Algorithms & Recursion
    Replies: 4
    Last Post: November 6th, 2011, 03:06 PM
  5. Vector Addition with small numbers giving NaN
    By Zula in forum What's Wrong With My Code?
    Replies: 4
    Last Post: October 28th, 2010, 09:29 PM