# I need some help with this programming problem

• May 26th, 2014, 01:39 PM
zackstyer
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:

Code :

```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); } }```
• May 26th, 2014, 01:51 PM
Norm
Re: I need some help with this programming problem
Quote:

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:
Code :

`int[] varName = new int[SizeOfArray];`
• May 26th, 2014, 01:59 PM
zackstyer
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};
• May 26th, 2014, 02:02 PM
Norm
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.
• May 26th, 2014, 02:05 PM
zackstyer
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.
• May 26th, 2014, 02:08 PM
Norm
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.
• May 26th, 2014, 02:13 PM
zackstyer
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.
• May 26th, 2014, 02:25 PM
Norm
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.
• May 26th, 2014, 02:35 PM
Cornix
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.
• May 26th, 2014, 04:50 PM
BharathA
Re: I need some help with this programming problem
Hi, kindly try the below coding...

[highlight code = Java]
...
[/highlight]