Check10A - { average /= unSorted.size();...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
import java.util.*; import java.io.*; i public class Check10A { public static void main(String[] args) { PrintStream out = System.out; Scanner in = new Scanner(System.in); List<Double> unSorted = new ArrayList<Double>(), sorted = new ArrayList<Double>(); double average = 0, buffer; out.println("Enter your integers\n(Negative=sentinel)"); while ((buffer = in.nextDouble()) >= 0) { unSorted.add(new Double(buffer)); average += buffer; } if (unSorted.size() > 0)
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: { average /= unSorted.size(); Collections.sort(unSorted); out.printf("The average is: %.1f%n", average); out.println("The sorted, distinct, above-average elements:"); for (Double index : unSorted) { if (!sorted.contains(index)) { sorted.add(index); out.printf("%s", (index > average) ? (index.intValue() + " ") : ""); } } out.printf("%n"); } else { out.println("Your list is empty!"); } } }...
View Full Document

This note was uploaded on 09/16/2011 for the course CSE CSE 1020 taught by Professor Burton,ma during the Fall '10 term at York University.

Ask a homework question - tutors are online