      1  import java.util.ArrayList;

      2  import java.util.Scanner;

      3

      4  /**

      5     This program reads a sequence of values and prints them, marking the largest value.

      6  */

      7  public class LargestInArrayList

      8  {

      9     public static void main(String[] args)

     10     {

     11        ArrayList<Double> data = new ArrayList<Double>();

     12

     13        // Read inputs

     14

     15        System.out.println("Please enter values, Q to quit:");

     16        Scanner in = new Scanner(System.in);

     17        while (in.hasNextDouble())

     18        {

     19           data.add(in.nextDouble());

     20        }

     21

     22        // Find the largest value

     23

     24        double largest = data.get(0);

     25        for (int i = 1; i < data.size(); i++)

     26        {

     27           if (data.get(i) > largest)

     28           {

     29              largest = data.get(i);

     30           }

     31        }

     32

     33        // Print all values, marking the largest

     34

     35        for (double element : data)

     36        {

     37           System.out.print(element);

     38           if (element == largest)

     39           {

     40              System.out.print(" <== largest value");

     41           }

     42           System.out.println();

     43        }

     44     }

     45  }