Muhaiminur
2/12/2018 - 11:58 PM

Not Taking Duplicate Number

Write a java program that reads 10 numbers from the user, but does not allow the user to enter duplicates. This means that if a number has been entered already, the program will not accept it as input again and instead ask the user to enter a different number.

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package BASICJAVA;

import java.util.Scanner;

/**
 *
 * @author ABIR
 */
public class Not_Taking_Duplicate_Number {
    public static void main(String[]args){
        Scanner abir =new Scanner(System.in);
        int[] number=new int[5];
        for (int i = 0; i < number.length; i++) {
            System.out.println("Enter your "+(i+1)+" number");
            int n=abir.nextInt();
            for (int j = 0; j <number.length; j++) {
                if(number[j]==n){
                    System.out.println("Duplicate Number");
                    n=abir.nextInt();
                }
            }
            number[i]=n;
        }
    }
}