Write a class with the following method: 1. boolean prime(int n) which returns true if n is prime and false if n is not prime...2.void call() to display all two digit twin prime numbers
Answers
Answer:
public class Prime
{public static boolean prime(int n)
{int c=0;
for (int i=1;i<=n;i++)
{if (n%i==0)
c=c+1;
}
if (c==2)
return true;
else
return false;
}
public void call()
{int a=10,b=99,c=11,d;
System.out.println("2 digit Twin prime numbers are ");
for (;a<=b;a++)
{if (prime(a))
{d=c;
c=a;
if ((c-d)==2)
System.out.println(d+","+c);
}
}
}
public static void main(String args[])
{Prime ob=new Prime();
ob.call();
}
}
Explanation:
Answer:
This is the prg
Explanation:
class Sol14
{
static boolean prime(int n)
{
int i,c=0;
for(i=1;i<=n;i++)
{
if(n%i==0)
c++;
}
if(c==2)
return true;
else
return false;
}
static int sum(int n)
{
int i,d,s=0;
for(i=n;i>0;i=i/10)
{
d=i%10;
s+=d;
}
return s;
}
static void call()
{
int i,s;
for(i=100;i<=999;i++)
{
s=sum(i);
if(prime(s)==true)
System.out.println(“Prime number:”+i);
}
}
}