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

• 07-20-2010, 08:53 PM
Gayathri12
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");
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
• 07-20-2010, 09:02 PM
PhHein
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.

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);```
• 07-21-2010, 06:00 AM
Eranga
Quote:

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.
• 07-21-2010, 08:19 AM
Gayathri12
thank u soo much
• 07-21-2010, 08:46 AM
Eranga
For what you are thanking ?
• 07-21-2010, 09:27 AM
Gayathri12
m thanking.......... PhHein
• 07-21-2010, 09:28 AM
Gayathri12
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.............