PROGRAM 4 : UNIQUE NUMBER
(UNIQUE NUMBER IS A NUMBER IN WHICH NO DIGIT IS REPEATED AND THE FIRST DIGIT IS NOT ZERO (0).
Example: 1234 , 45631 are unique numbers.
11234 , 15675 0987 , are not unique number as one or more digits occur more than once or the first digit is '0' )
PROGRAM:
import java.io.*;
public class unique_number
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number to find out whether it is an unique number or not:");
String s = br.readLine();
int l = s.length() , f = 0;
for(int i = 0 ; i < l ; i++){
for(int j = i+1 ; j < l ; j++){
if(s.charAt(i)==s.charAt(j) || s.charAt(0)=='0'){
f++;
break;
}
}
}
if(f==0)
System.out.println("The number is an unique number.");
else
System.out.println("The number is not an unique number.");
}
}
(UNIQUE NUMBER IS A NUMBER IN WHICH NO DIGIT IS REPEATED AND THE FIRST DIGIT IS NOT ZERO (0).
Example: 1234 , 45631 are unique numbers.
11234 , 15675 0987 , are not unique number as one or more digits occur more than once or the first digit is '0' )
PROGRAM:
import java.io.*;
public class unique_number
{
public static void main(String args[])throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a number to find out whether it is an unique number or not:");
String s = br.readLine();
int l = s.length() , f = 0;
for(int i = 0 ; i < l ; i++){
for(int j = i+1 ; j < l ; j++){
if(s.charAt(i)==s.charAt(j) || s.charAt(0)=='0'){
f++;
break;
}
}
}
if(f==0)
System.out.println("The number is an unique number.");
else
System.out.println("The number is not an unique number.");
}
}
No comments:
Post a Comment