Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help me to write this program in Java!!! (Duplicate Elimination) Use a on

ID: 3659921 • Letter: P

Question

Please help me to write this program in Java!!! (Duplicate Elimination) Use a one dimensional array to solve the following problems: Write an application that inputs five numbers, each between 10 and 100, inclusive. As each number is read, display it only if it's not a duplicate of a number already read. Provide for the "worst case", in which all five numbers are different. Use the smallest possible array to solve this problem. Display the complete set of unique values input after the user enters each new value.

Explanation / Answer

/*100% running, short and sweet code, i think this may help you*/

import java.util.Arrays;
import java.util.Scanner;

public class DuplicateElimination {

    static void printUnique(int[] array) {
        int i;
        Arrays.sort(array);
        for (i = 1; i < array.length; i++) {
            if (array[i] != array[i - 1]) {
                System.out.print(array[i - 1] + " ");
            }
        }
        System.out.print(array[i - 1]);
    }

    public static void main(String[] args) {
        int[] array = new int[5];
        int temp;
        Scanner input = new Scanner(System.in);
        System.out.println("Enter any 5 digit between 10 to 100");
        for (int i = 0; i < array.length; i++) {
            do {
                System.out.println("Enter element " + (i + 1) + " :");
                temp = input.nextInt();
                if (temp >= 10 && temp <= 100)
                    array[i] = temp;
                else
                    System.out.println("Entered Invalid number");
            } while (temp < 10 || temp > 100);
        }
        System.out.print(" Unique Elements are :");
        printUnique(array);
    }
}