Kushal N.

asked • 04/03/18

What is wrong in this program ?

import java.util.*;
class Twin
{
int n=0;
int c=0;
int Is_Prime(int a)
{
for(int i=1;i<=a;i++)
{
if(a%i==0)
c=c+1;
}
if(c==2)
return 1;
else
{
return 2;
}
}
}
public class Twin_prime
{
public static void main()
{
Scanner obj=new Scanner(System.in);
Twin t=new Twin();
System.out.println("Enter a number");
int a=obj.nextInt();
System.out.println("Enter another number");
int b=obj.nextInt();
int c=t.Is_Prime(a);
if(c==1)
c=a;
else
c=0;
int d=t.Is_Prime(b);
if(d==1)
d=b;
else
d=0;
int min=c>d?d:c;
int max=c>d?c:d;
if(Math.abs(max-min)==2)
System.out.println("Twin Primes");
else
System.out.println("Not Twin Primes");
}
}

1 Expert Answer

By:

Patrick B. answered • 07/15/19

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.