This program won't execute

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Sachu1996
    New Member
    • Jun 2010
    • 3

    #1

    This program won't execute

    Code:
    public class Twins
    {
      public static void main(String args[])
      { 
        int a,b,c;
        a=1;
        b=3;
        for(c=2;c<=97;c++)
        {
          if(a%c==0&&b%c==0)
            System.out.println(a+" and "+b+" are prime twins");
          a++;
          b++; 
        }
      }
    }

    This was a program to find all the twin prime no.s till 100. It is compiling but when I right click and void main(), nothing happens. Can someone please help me.
    Last edited by Frinavale; Sep 28 '10, 05:02 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags and indentation to code posted.
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    The logic you have written for finding a twin prime is wrong. The code has no flaws. It is not in this way you should calculate a twin prime. Twin prime are serious like 3,5;5,7;11,13. You have to change your logic.

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • Sachu1996
      New Member
      • Jun 2010
      • 3

      #3
      what do you mean the logic is wrong. it is the correct logic.

      Comment

      • Oralloy
        Recognized Expert Contributor
        • Jun 2010
        • 988

        #4
        Sachu1996,

        Your logic is wrong.

        Simply step through the code with a=3 and b=5 to see why it fails.

        Good Luck!

        Comment

        Working...