Array-promo

Question

Write a Program in Java to input a number and check whether it is a Unique Number or not in a given range.

( A Unique number is a positive integer (without leading zeros) with no duplicate digits. For example 7, 135, 214 , 5243 are all unique numbers whereas 33, 3121, 200 are not.)

				
					Enter Lower lower :
1000
Enter Upper value :
1100
Unique numbers between 1000 and 1100
1023  1024  1025  1026  1027  1028  1029  1032  1034  1035  1036  1037  1038  1039  1042  1043  1045  1046  1047  1048  1049  1052  1053  1054  1056  1057  1058  1059  1062  1063  1064  1065  1067  1068  1069  1072  1073  1074  1075  1076  1078  1079  1082  1083  1084  1085  1086  1087  1089  1092  1093  1094  1095  1096  1097  1098 
				
			

Share code with your friends

Share on whatsapp
Share on facebook
Share on twitter
Share on telegram

Code

				
					 import java.util.*;

public class UniqueNumberInRange

{

    public static void main(String args[] )

    {
        int lowerRange=0,UpperRange=0;
        Scanner sc=new Scanner(System.in);
        System.out.println("Enter Lower lower :");
        lowerRange=sc.nextInt();
        System.out.println("Enter Upper value :");
        UpperRange=sc.nextInt();
        int flag=0,i, j,temp=0,count=0,r=0;
        System.out.println("Unique numbers between "+lowerRange+" and "+UpperRange);
        for(i=lowerRange;i<=UpperRange;i++)
        {
            flag=0;
            for(j=0;j<=9;j++)
            {
            temp=i;
            count=0;
            while(temp>0)
            {
                r=temp%10;
                if(r==j) /* if any digits are repeated, then it is not a UniqueNumber*/

                { 
                    count=count+1;
                }
                temp=temp/10;
            }
            if(count>1)
            {
                
                flag=1;
                break;
            }

            }

            if(flag ==0)
            {
                System.out.print(i+"  ");
            }

        }
    }
}


				
			

Coding Store

Leave a Reply

Your email address will not be published. Required fields are marked *