Results 1 to 7 of 7
- 07-20-2010, 07:53 PM #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
- 07-20-2010, 08:02 PM #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.
Math problems? Call 1-800-[(10x)(13i)^2]-[sin(xy)/2.362x]
The Ubiquitous Newbie Tips
- 07-21-2010, 05:00 AM #3
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 07-21-2010, 07:19 AM #4
Member
- Join Date
- Jul 2010
- Posts
- 5
- Rep Power
- 0
thank u soo much
- 07-21-2010, 07:46 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 07-21-2010, 08:27 AM #6
Member
- Join Date
- Jul 2010
- Posts
- 5
- Rep Power
- 0
m thanking.......... PhHein
- 07-21-2010, 08:28 AM #7
Member
- Join Date
- Jul 2010
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Execute code from ActionListener
By Viola in forum New To JavaReplies: 3Last Post: 05-29-2010, 05:10 PM -
Unable to change the system time in Ubuntu using the given code
By manojpant2002 in forum New To JavaReplies: 2Last Post: 01-09-2010, 06:05 AM -
Compile/Execute code in Java app
By Doctor Cactus in forum New To JavaReplies: 5Last Post: 12-16-2008, 09:58 AM -
Unable to execute command line command in java
By LordSM in forum New To JavaReplies: 1Last Post: 08-08-2007, 12:23 AM -
error stack when I try to execute my code
By paty in forum New To JavaReplies: 1Last Post: 08-02-2007, 08:32 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks