Given a number N containing even number of digits. The task is to check whether that number is palindrome or not.
Input : N = 10239876540022
Output : Yes
Explanation: N contains all the digits from 0 to 9. Therefore, it is a pangram.
Simple Approach:
1. Given a number containing digits from 0 to 9 in any order.
2. We need to first convert it into string type by using method String.valueOf(int);
3. After that create one HashSet of type Character and add all character from String to set.
4. After adding all the character from string set simply check if size of hashset is == 10 or not if yes then given number is panagram else not.
5. We used hashset here because in hashset duplicates values are not allowed.
Let’s have a look at code:
package basic;
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;
/**
* @author prajwal
*
*
* If the given number contains all the number from[0-9] then it is panagram number
*
*/
public class PanagramNumber {
/**
* @param args
*/
static boolean checkPanagram(long n) {
String str = String.valueOf(n);
Set<Character> mySet = new HashSet<>();
for(int i=0; i<str.length(); i++) {
mySet.add(str.charAt(i));
}
if(mySet.size() == 10)
return true;
else
return false;
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
long n = sc.nextInt();
boolean ans = checkPanagram(n);
if(ans == true) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}
Thank You..!