Number Count and Printing Numbers without Repeated/Duplicates numbers in JAVA .



PROBLEM : You have to count how many non-repeated/no duplicate numbers in a given set or range. You also have to print thosenumbers.

INPUT EXAMPLE: How many digits you want to test(RANGE)?
--->  5
Please input value = 1

Please input value = 3

Please input value = 2

Please input value = 1

Please input value = 3

OUTPUT EXAMPLE : 
1
3
2
Total 3 Numbers

HERE IS THE CODE :

import java.util.Scanner;
public class Pro_duplicateArray{
      public static void main (String[] args){
            Scanner keyboard = new Scanner (System.in);
            System.out.println("How many digits you want to test(RANGE)?");
            int range = keyboard.nextInt();
                                                              /** mother_array = a (you can chose) 
                                                                   *copy_array = c (you can chose)
                                                                   *printing_array = b (you can chose)**/
            int[] mother_array = new int [range];  
            int [] copy_array = new int [range];  
            int [] printing_array = new int [range];   
                                                    /** mother_array and copy_array's value will be same
                                                         *printing_array's all value is initialized 0
                                                          *as no value was inputted on printing_array**/
            for (int i=0; i< mother_array.length; ++i ){ 
                  
                  System.out.println("please input value");
                  int value = keyboard.nextInt();
                  mother_array[i] = value; 
                  copy_array[i]=value ;  
            }                                
            for (int i=0; i < mother_array.length; ++i){
                  for (int j=0; j<mother_array.length;++j){
                        if (mother_array[i]==copy_array[j]){
                              printing_array[i] = copy_array [j];
                              copy_array[j] = 0 ;
                        }
                  }  
            }
            int count = 0 ; 
            for (int i=0; i < printing_array.length; ++i){
                  if (printing_array[i]>0){
                        System.out.println(printing_array[i]);
                        count++;
                  }
            }
            System.out.printf("Total %d Numbers%n[NO REPITATION TAKEN]",count);
      }
}

Any Suggestions Regarding Code: 

Comments

Popular posts from this blog

All about Xiaomi ROM Flash [in Bangla Language]

Windows ready হতে অনেক সময় নেয় [SOLVED]