Computer Science, asked by oishikmuk735, 1 year ago

Wap in java to print the minimum prime digit of a number

Answers

Answered by Anonymous
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 ?
Anonymous: yes to check whether the number is prime or not , u need to use counter variable !
Similar questions