Wrox Programmer Forums
| 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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #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
  #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.

  #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);
  }
  #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



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





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