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
Post a Comment