need to find "number of unique digit numbers" present in the given range in java?

Viewed 7
import java.util.Scanner;
import java.util.Arrays;

class FindUniqueNumbers{
public static void main(String[] args) {
    int start,end;
    Scanner ob = new Scanner(System.in);
    System.out.println("Enter start value:");
    start = ob.nextInt();
    System.out.println("Enter end value:");
    end = ob.nextInt();

    //0 - 9 ----> 10 (Creating an array of size 10)

    boolean check[] = new boolean[10];
    Arrays.fill(check,false);
    int duplicate;
    for(int i=start;i<=end;i++){
        Arrays.fill(check,false);
        duplicate = i;
        int flag = 0;
        while(i!=0){
            int rem = i%10;
            if(check[rem]==true){
                flag = 1;
                break;
            }
            else{
                check[rem] = true;
                i = i/10;
            }

        }
        Arrays.fill(check,false);
        if(flag==0){
            System.out.print(duplicate+" ");
        }
    }
    System.out.println();
}
} 

I wrote the above code in java... I used Arrays class fill method to initialize the array.i.e.,Arrays.fill(check,false);

when I used the fill method inside the for loop, then the code is running infinitely. So, please could anyone help me to know why it is running infinite time.

I have uploaded the code.

0 Answers
Related