find portait

import java.util.ArrayList;

public class ListOfPictures
{
    public static void main(String[] args)
    {
        ArrayList<Picture> gallery = new ArrayList<Picture>();
        gallery.add(new Picture("degas1.jpg"));
        gallery.add(new Picture("gaugin1.jpg"));
        gallery.add(new Picture("monet1.jpg"));
        gallery.add(new Picture("monet2.jpg"));
        gallery.add(new Picture("renoir1.jpg"));
        
        // Your code here
        Int count = 0;
        for(Picture pic: gallery)
        {
            if ( pic.getHeight() > pic.getWidth())
            {
                counter++;
            }
        }
        System.out.println("Pictures with portrait orientation: " + count);
    }
}

find match
i = 0
found = false
while not found and i < size if ith element matches found = true else i++ if found, then i is index of of match

import java.util.ArrayList;

public class ListOfPictures
{
    public static void main(String[] args)
    {
        ArrayList gallery = new ArrayList();
        gallery.add(new Picture(“degas1.jpg”));
        gallery.add(new Picture(“gaugin1.jpg”));
        gallery.add(new Picture(“monet1.jpg”));
        gallery.add(new Picture(“monet2.jpg”));
        gallery.add(new Picture(“renoir1.jpg”));
        
        int i = 0;
        boolean found = false;
        
        while (!found && i < gallery.size())
        {
            Picture pic = gallery.get(i)
            if(pic.getHeight() > pic.getWidth())
            {
                found = true;
            }
            else
            {
              i++;
            }
        }
        
        if (found)
        {
            gallery.get(i).draw();
        }
    }
}

arrya list

import java.util.ArrayList;

public class ListOfPictures
{
    public static void main(String[] args)
    {
        ArrayList<Picture> gallery = new ArrayList<Picture>();
        gallery.add(new Picture("degas1.jpg"));
        gallery.add(new Picture("gaugin1.jpg"));
        gallery.add(new Picture("monet1.jpg"));
        gallery.add(new Picture("monet2.jpg"));
        gallery.add(new Picture("renoir1.jpg"));

        ArrayList<Picture> matches = new ArrayList<Picture>();
        for(Picture pic: gallery)
        {
            if(pic.getHeight() > pic.getWidth())
            {
                matches.add(pic);
            }
        }

        int rightmostX = 0;
        for (Picture pic : matches)
        {
            pic.translate(rightmostX + 10, 0);
            rightmostX = pic.getMaxX();
            pic.draw();
        }
    }
}
    public String getFriends(String separator)
    {
        String separatedFriends = "";
        for (int i = 0; i < friends.size(); i++)
        {
          if (i > 0)
          {
            separatedFriends = separatedFriends + separator + friend.get(i);
          }
          else 
          {
            separatedFriends = separatedFriends + friend.get(i);
          }
        }
    }
public void unfriend(Person nonFriend)
{
   int nonFriendIndex = find(nonFriend);
   if (nonFriendIndex != -1)
   {
     friends.remove(nonFriendIndex);
   }   
}

use find

public void talkTo(Person person)
{
    int oldIndex = find(person);
    if(oldIndex != -1)
    {
      friends.remove(oldIndex);
      friends.add(0, person);
    }
}