# Thread: Unable to execute my code can u plz help me out

1. Member
Join Date
Jul 2010
Posts
5
Rep Power
0

## 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. 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 08:05 PM.

3. Originally Posted by Gayathri12
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. Member
Join Date
Jul 2010
Posts
5
Rep Power
0
thank u soo much

5. Member
Join Date
Jul 2010
Posts
5
Rep Power
0
m thanking.......... PhHein

6. Member
Join Date
Jul 2010
Posts
5
Rep Power
0
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.............

#### Posting Permissions

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