/****************************************************************************** * Name: COS 126 Staff * NetID: cos126 * Precept: P00 * * Fall 15 Programming Exam 1, part 1 * Count distinct integers entered from standard input. * Input is sorted. *****************************************************************************/ public class Count1 { public static void main(String[] args) { int count = 1; // number of integers input int distinct = 1; // number of distinct integers // read first int int val = StdIn.readInt(); // don't know how many. read and count till done while (!StdIn.isEmpty()) { int newVal = StdIn.readInt(); count++; if (newVal != val) { // found a new one distinct++; val = newVal; } } // output StdOut.println(distinct + " distinct values among " + count + " integers"); } }