Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Java > Other Java > Java GUI
Password Reminder
Register
| FAQ | Members List | 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 Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 10th, 2007, 04:11 PM
Registered User
Points: 17, Level: 1
Points: 17, Level: 1 Points: 17, Level: 1 Points: 17, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2007
Location: Middelburg, Mpumalanga, South Africa.
Posts: 3
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
Reply With Quote
  #2 (permalink)  
Old May 13th, 2007, 04: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.

Reply With Quote
  #3 (permalink)  
Old May 14th, 2007, 11:57 PM
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);
  }
Reply With Quote
  #4 (permalink)  
Old May 15th, 2007, 12: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

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Static methods spinjob BOOK: Professional C++ 7 March 12th, 2009 02: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 12th, 2007 11:15 PM
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 11:10 AM



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


Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.