Results 1 to 7 of 7
  1. #1
    Gayathri12 is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default Unable to execute my code can u plz help me out

    program that takes a 3 digit number n and finds out whether
    the number 2^n + 1 is prime, or if it is not prime find out its
    factors.


    package javaapplication7;

    import java.io.*;

    public class Main
    {



    private static void main(String[] args)

    {
    int num = 0;
    String str = "";
    System.out.println("Enter a 3 digit number");
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    str = in.readLine();..............> (it shows me an error at this line )
    num = Integer.parseInt(str);
    CheckPrime(num);

    }

    private static void CheckPrime(int num)
    {
    boolean isprime = false;
    for (int i = 2; i < num; i++)
    {
    if(i%2==0 || (i+1)%2==0)
    {
    if ((num % i) == 0)
    {
    System.out.println("Entered number is not a prime");
    Factors(num);
    isprime = false;
    break;
    }
    else
    {

    isprime = true;
    }
    }


    }
    if (isprime)
    {
    System.out.println("Entered number is a prime");
    }
    }

    private static void Factors(int num)
    {
    System.out.println("Factors of " + num + " are :");
    for (int i = 1; i < num; i++)
    {

    if ((num % i) == 0)
    {
    if (i > (num / i))
    {
    break;
    }
    else
    {
    System.out.println(i + "*" + num/i);
    }
    }

    }

    }
    }

    can u plz help me out in solving this

  2. #2
    PhHein's Avatar
    PhHein is offline Senior Member
    Join Date
    Apr 2009
    Location
    Germany
    Posts
    1,429
    Rep Power
    7

    Default

    It won't become any more obvious. And when you get a compiler error, post the exact error message, so that we don't have to guess what it is.

    Java Code:
    System.out.println("Enter a 3 digit number");
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    try {
    	str = in.readLine();
    	num = Integer.parseInt(str);
    } catch (NumberFormatException e) {
    	e.printStackTrace();
    } catch (IOException e) {
    	e.printStackTrace();
    }
    CheckPrime(num);
    Last edited by PhHein; 07-20-2010 at 09:05 PM.
    Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
    The Ubiquitous Newbie Tips

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by Gayathri12 View Post
    can u plz help me out in solving this
    What's your question here, on what you stuck with? Can you explain bit more, not the original task, things you've stuck.

  4. #4
    Gayathri12 is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    thank u soo much

  5. #5
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

  6. #6
    Gayathri12 is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    m thanking.......... PhHein

  7. #7
    Gayathri12 is offline Member
    Join Date
    Jul 2010
    Posts
    5
    Rep Power
    0

    Default

    program that takes a 3 digit number n and finds out whether
    the number 2^n + 1 is prime, or if it is not prime find out its
    factors. this is the question.............

Similar Threads

  1. Execute code from ActionListener
    By Viola in forum New To Java
    Replies: 3
    Last Post: 05-29-2010, 06:10 PM
  2. Replies: 2
    Last Post: 01-09-2010, 07:05 AM
  3. Compile/Execute code in Java app
    By Doctor Cactus in forum New To Java
    Replies: 5
    Last Post: 12-16-2008, 10:58 AM
  4. Unable to execute command line command in java
    By LordSM in forum New To Java
    Replies: 1
    Last Post: 08-08-2007, 01:23 AM
  5. error stack when I try to execute my code
    By paty in forum New To Java
    Replies: 1
    Last Post: 08-02-2007, 09:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •