p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > Java > Other Java > Java GUI
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 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
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old 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
Default

Hi i am also looking for the same answer, if you have any info that could help me please let me know. thanx.

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old 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
Default

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);
  }
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old 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
Default

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Static methods spinjob BOOK: Professional C++ 7 March 12th, 2009 03:16 PM
two methods different results hahaha568 BOOK: Beginning SQL 0 February 10th, 2008 09:47 AM
Dispose() methods bpevangelista BOOK: Professional XNA Game Programming: For Xbox 360 and Windows ISBN: 978-0-470-12677-6 2 May 13th, 2007 12:15 AM
Treeview Methods goldwinger C# 2005 0 December 29th, 2005 10:00 AM
Please help me with web methods DiegoF .NET Web Services 3 April 10th, 2004 12:10 PM



All times are GMT -4. The time now is 04:27 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc