Skip to main content

UNIQUE NUMBER

PROGRAM : UNIQUE NUMBER

A Number is Said to be unique if
1- it do not start with 0.
2- it do not have any repeating digit.

for example:
0112 is not a unique no.                         1234 is a unique no. 

SYNTAX:


import java.io.*;
class unique_num
{
    public static void main(String args[])throws IOException
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        String s;int val=0;
        System.out.println("Enter a Number");
        s=br.readLine();
        if(s.charAt(0)=='0')
        System.out.println("**** The Number is Not a Unique Number ****");
        else
        {
            for(int i=0;i<s.length();i++)
        {
            for(int j=i+1;j<s.length();j++)
            {
                if(s.charAt(i)==s.charAt(j)) //if any digits match, then we know it is not a Unique Number
                {
                    val=1;
                    break;
                }
            }
        }

        if(val==0)
        System.out.println("**** The Number is a Unique Number ****");
        else
        System.out.println("**** The Number is Not a Unique Number ****");

    }
}}

Comments

Popular posts from this blog

SMITH NUMBER

PROGRAM: SMITH NUMBER A   Smith number  is a composite number, the sum of whose digits is the sum of the digits of its prime factors obtained as a result of prime factorization (excluding 1). The first few such numbers are 4, 22, 58, 85, 94, 121 ……………….. For Example 58=> 5+8=13 2+(2+9) of 29 =13 Since sum of digits=sum of digits of prime factors 58 is a SMITH NUMBER SYNTAX: import java.io.*; class smith_no { static int sum,sum1;     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n;int c=0;         System.out.println("Enter a Number");         n=Integer.parseInt(br.readLine());         int n1=n;         while(n1!=0){         int d=n1%10;         sum1+=d; ...

Disarium Number

AJ Java Programs Program 4: Disarium Number A number will be called DISARIUM if sum of its digits powered with their respective position is equal to the original number. For example  135 is a DISARIUM (Workings 1 1 +3 2 +5 3  = 135, some other  DISARIUM  are 89, 175, 518 etc) Syntax: import java.io.*; class disarium {     public static void main(String args[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n,n1,n2,c=0,sum=0,d=0;         System.out.println("Enter a Num");         n=Integer.parseInt(br.readLine());         n2=n1=n;         while(n2!=0)         {             n2=n2/10;             c++;         }       ...

MAGICAL/ MAGIC NUMBER USING RECURSION

PROGRAM :  MAGICAL NUMBER BY RECURSION This  program  checks if a  number  is a  Magic number  in  JAVA . A  number  is said to be a  Magic number  if the sum of its digits are calculated till a single digit is obtained by recursively adding the sum of its digits. If the single digit comes to be 1 then the  number  is a  magic number . Example: 10999 => 1+0+9+9+9=28=>2+8=>10=>1+0= 1                  199    =>1+9+9 =>19=> 1+9=>10=>1+0= 1 SYNTAX import java.io.*; class magic  {    static int c;     public static void main(String arsg[])throws IOException     {         BufferedReader br=new BufferedReader(new InputStreamReader(System.in));         int n;int d=0;int m;         System.out.println("ENter a NUmber");   ...