In this program, user will will enter any number and program will display the minimum prime digit present in the number.
import java.util.*;
class MPrime
{
int min=11;
public void show(int n)
{
for(int i=n;i>0;i=i/10)
{
int c=i%10;
if(prime(c) &&
c< min)
min=c;
}
if(min!=11)
System.out.println("\nMinimum prime digit="+min);
else
System.out.println("\nNo
prime digit.");
}
boolean prime(int no)
{
int c=0;
for(int j=1;j<=no;j++)
{
if(no%j==0)
c++;
}
if(c==2)
return true;
else
return false;
}
public static void main(String args[])
{
MPrime ob=new MPrime();
Scanner sc=new
Scanner(System.in);
System.out.print("\nEnter the number:
");
int n=sc.nextInt();
ob.show(n);
}
}
No comments:
Post a Comment