Wap in java to print the minimum prime digit of a number
Answers
Answered by
5
Code
import java.util.*;
class Prime_digits_only
{
public void main()
{
Scanner sc=new Scanner ( System.in);
System.out.println("Enter a number");
int n=sc.nextInt();
int cpy=n;
int min=9;
int c=0;
int d=0;
int f=0;
while(n>0)
{
d=n%10;
if(d<min)
{
min=d;
c=0;
for(int i=1;i<=d;i++)
{
if(d%i==0)
{
c++;
}
}
}
if(c==2)
{
f=1;
}
}
if(f==1)
{
System.out.println("The smallest prime digit = "+d);
}
}
}
Output
Enter a number
56781
The smallest prime digit = 5
Hope it helps
________________________________________________________________________
oishikmuk735:
While checking for the minimum number you used the counter......is it necessary ?
Similar questions