|
|
 |
| Java GUI Discussions specific to programming Java GUI. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Java GUI section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

May 10th, 2007, 05:11 PM
|
|
Registered User
|
|
Join Date: May 2007
Location: Middelburg, Mpumalanga, South Africa.
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
METHODS
Hi Guys. Im new to java. How do you write method that determines whether a number is a prime. It should displays all prime numbers less than 10,000.
MAGAGULA DF
__________________
MAGAGULA DF
|

May 13th, 2007, 05:29 AM
|
|
Authorized User
|
|
Join Date: May 2007
Location: East London, Eastern cape, South Africa.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi i am also looking for the same answer, if you have any info that could help me please let me know. thanx.
|

May 15th, 2007, 12:57 AM
|
|
Authorized User
|
|
Join Date: Oct 2006
Location: Yerevan, , Armenia.
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Not a GUI question :)
Prime number has only two divisors(1 and the number itself). So number i isn't prime if it divides on any number less than i/2 without the remainder. The algorithm of checking either number is prime or not is based on that.
For the Java particulary I suggest method below:
public void isPrime(int i) {
int isPrime = 0;
for (int j = 2; j <= i/2; j++) {
if (i%j == 0) {
isPrime = 1;
break;
}
}
if (isPrime == 0) System.out.println(i);
}
|

May 15th, 2007, 01:53 PM
|
|
Authorized User
|
|
Join Date: May 2007
Location: East London, Eastern cape, South Africa.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Thanx, shame i didnt expect you to right the program for me but atleast now i can learn from it for my next program..im really battling with my quistions. i just wish my lecturer would respond to my questions...its quite difficult to learn java on your own.thanx again
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |