// Brent Cooley // CPS 406 - Assignment 2 - NoDups.java // This class asks the user to input 20 integers. All duplicates // are then removed and the remaining numbers are printed to the screen ///////////////////////////////////////////////////////////////////////// import java.io.*; public class NoDups { ////////////////////////////////////////////////////////////////////// // Class variables public final static int max = 20; // max numbers to input ////////////////////////////////////////////////////////////////////// // readNumber() - reads in an integer from the keyboard - returns // an integer public static int readNumber() { StringBuffer userinputbuffer = new StringBuffer(); // to hold chars int userinput = -1; char ch; try { Reader inreader = new InputStreamReader(System.in); // continue reading in characters until a carriage return is read while((ch = (char)inreader.read()) != '\n') userinputbuffer.append(ch); // append char onto buffer } catch(Exception ex) { System.out.println("Error reading number"); } try { // convert buffer to a string and trim whitespace; convert to an integer userinput = Integer.valueOf(userinputbuffer.toString().trim()).intValue(); } catch(Exception ex) { System.out.println("That is not an integer"); } return userinput; } //////////////////////////////////////////////////////////////////// // memberOf(..) - returns true if the integer num is found in the // array numbers private static boolean memberOf(int num, int numbers[]) { for(int i=0; i 100)) { System.out.println("Between 10 and 100 please."); --i; } else { numbers[i] = num; } } // print out results System.out.println("\n---------------------------------------------\nNumbers entered:"); printArray(numbers); System.out.println("\nNow removing dups..."); printArray(removeDups(numbers)); System.out.println("---------------------------------------------\n"); } }