Reputation: 1
This is the code I'm trying to use in Bluej to return values higher than my target value:
import java.util.ArrayList;
public class BiggestValue
{
public ArrayList<Integer> getBiggerValues (int target, ArrayList<Integer> list)
{
ArrayList<Integer> result = new ArrayList<Integer> ();
for (int ix=0; ix < list.size(); ix++)
{
int currentItem = list.get(ix);
if (currentItem > target)
{
result.add (currentItem);
}
}
return result;
}
}
It compiles but when I put in values to get the result I get the following message:
can anyone help? Thanks Lydia
Upvotes: 0
Views: 157
Reputation: 3171
You could pass new ArrayList<Integer>(Arrays.asList(new Integer[]{14, 19, 20}))
as the second parameter or you could write a main
method as shown below:
public static void main(String args[]){
BiggestValue bV = new BiggestValue();
ArrayList bigs = bV.getBiggerValues(17, new ArrayList<Integer>(Arrays.asList(new Integer[]{14, 19, 20})));
//methods to display the output.
}
Upvotes: 1