L.Taylor
L.Taylor

Reputation: 1

When I use bluej to try and return values higher than my target value from my Array List it says Error: <identifier> expected

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:

enter image description here

can anyone help? Thanks Lydia

Upvotes: 0

Views: 157

Answers (1)

Blip
Blip

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

Related Questions