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.

Results 1 to 10 of 10

Thread: I need some help with this programming problem

  1. #1
    Junior Member
    Join Date
    May 2014
    Location
    Romania
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default I need some help with this programming problem

    Greetings. I need some help with a programming problem I'm solving. The problem sounds like this:

    Gyazo - c42a2235b5aa7285a94d8eb7748831a6.png


    I know how to solve it in my head but I don't know how to translate it into Java language due to lack of experience (2 weeks). My solution I've formed in my head is: create a new array for the numbers that are in improvement and then declare a "max" variable. Check which array's length is higher and print that length. What I don't know to do is: I don't know how to create a new array for each numbers that are passing through the condition.

    Note: I couldn't find anything on internet about my problem so that's why I'm here.

    My code is this one:

    class MyClass {
     
     static int progresie=0;
     
        public static void longest_improvement(Integer[] grades) {
     
            for(int i=0;i<grades.length-1;i++){
    			if(grades[i]<=grades[i+1]){
    				progresie ++;
     
    			}
    		}
    			System.out.println(progresie);
        }
    }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I need some help with this programming problem

    how to create a new array for each numbers that are passing through the condition.
    Are you asking how to create an array large enough to hold the numbers that pass? When you have determined the size of the array,
    Use the new statement to create an array:
    int[] varName = new int[SizeOfArray];
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member
    Join Date
    May 2014
    Location
    Romania
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need some help with this programming problem

    No. I want to create an array for each sequence of numbers that are passing through the condition.

    For example: 1,2,3,1,4,5,2,3,1

    The arrays created are: 1. {1,2,3}
    2. {1,4,5}
    3. {2,3};

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I need some help with this programming problem

    If you need 3 arrays, then you will need to use the new statement 3 times, once for each array.
    If you don't understand my answer, don't ignore it, ask a question.

  5. #5
    Junior Member
    Join Date
    May 2014
    Location
    Romania
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need some help with this programming problem

    This is the thing. I'm making the program on "www.talentbuddy.co" a site with problems where you write your code in their field and the variables and arrays you need are generated by them. The array is different on each "Check solution" button.

    Gyazo - 4a884c05e39ac81055bd5cf41f08e1e0.png

    I don't wanna make any advertise but this website is good for anyone who's learning a new programming language.

  6. #6
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I need some help with this programming problem

    Sorry, I don't go to other sites. Post anything here that shows what your problem is.
    If you don't understand my answer, don't ignore it, ask a question.

  7. #7
    Junior Member
    Join Date
    May 2014
    Location
    Romania
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: I need some help with this programming problem

    This is my problem.... I get a random array and my code should be general not for one particular array.

  8. #8
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: I need some help with this programming problem

    The code would determine what arrays need to be created and how large each one should be.
    If you don't understand my answer, don't ignore it, ask a question.

  9. #9
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: I need some help with this programming problem

    If you do not know the number of elements up ahead you should use a list instead of an array. If the api explicitely calls for an array you can convert the list back to an array later.
    Using lists your problem will become trivial.

  10. #10
    Junior Member
    Join Date
    May 2014
    Location
    Chennai
    Posts
    9
    My Mood
    Cool
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: I need some help with this programming problem

    Hi, kindly try the below coding...

    [highlight code = Java]
    ...
    [/highlight]
    Last edited by copeg; May 27th, 2014 at 11:48 AM. Reason: Removed spoonfed code

Similar Threads

  1. java game programming problem 1
    By swikot in forum What's Wrong With My Code?
    Replies: 4
    Last Post: January 1st, 2014, 11:27 AM
  2. how do i solve this programming problem in dr java?
    By jennavg in forum What's Wrong With My Code?
    Replies: 4
    Last Post: April 8th, 2013, 12:22 PM
  3. [SOLVED] Problem in socket programming
    By sinni in forum Java Networking
    Replies: 1
    Last Post: March 15th, 2011, 10:26 AM
  4. [SOLVED] Socket Programming Problem
    By relixus in forum What's Wrong With My Code?
    Replies: 7
    Last Post: December 9th, 2010, 10:35 PM
  5. Newbie Programming problem
    By Pingu in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2010, 02:10 AM