Showing posts with label Full Prime Number in Java. Show all posts
Showing posts with label Full Prime Number in Java. Show all posts

Full Prime Number in Java

Write a program to input an integer from the user, and check if that number is a full prime. A number is said to be a full prime if it is a prime number and all its digits are also prime numbers. For example, 23 is a full prime number because 23 itself is prime, and all its digits 2, 3 are also prime.
 import java.io.*;
 class FullPrime
{
 public static void main(String args[])throws IOException
{
 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
 System.out.print("Enter the number: ");
 int num = Integer.parseInt(br.readLine());
 if(isPrime(num))
{
 int n = num; 
 loop:
 while(n != 0)
{
 int d = n % 10;
 switch(d)
{
 case 2:
 case 3:
 case 5:
 case 7:
 n /= 10;
 break;
 default:
 break loop;
 }
 }
 if(n == 0)
 System.out.println(num + " is full prime.");
 else
 System.out.println(num + " is not full prime.");
 }
 else 
 System.out.println(num + " is not full prime.");
 }
 public static boolean isPrime(int n)
{
 int f = 0;
 for(int i = 1; i <= n; i++)
 if(n % i == 0) 
 f++; 
 }
 return f == 2;
 }
 }

Second largest number in java using ternary operator

 //Largest second number using ternary operator public class Main { public static void main(String[] args) { int a=5,b=6,c=7; int ...