Java Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingJava Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 14th, 2008, 10:04 AM
JOHANNA JOHANNA is offline
Registered User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 1 JOHANNA User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 3 m 51 sec
Reputation Power: 0
Prime numbers using arrays

This is Question??
The Sieve of Eratosthenes is an ancient Greek algorithm for deriving the list of
prime numbers up to a certain point. The algorithm works as follows:

1. Create an empty list of known prime numbers
2. Create a list of numbers from 2 up to the maximum number you wish to
test.
3. Add 2 to the list of known prime numbers and then mark of every
multiple of 2 as tested for primality.
4. The next unmarked number in the list is prime, however all its
subsequent multiples are not. Add this number to the known primes list
and mark all its multiples accordingly.
5. Repeat step 4 until no untested numbers remain in the list. Once you
reach the square root of the maximum number being tested all
remaining numbers in the list will be prime.

Implement the above algorithm using the Java Programming language.
Create a PrimeCandidate class which encapsulates an integer value as
well as an indication as to whether or not it has been tested for primality. Use
appropriate information hiding techniques. Represent the list of numbers to be tested as an array of PrimeCandidate and the list of known primes as an
ArrayList. Create a suitable user interface to demonstrate your practical, it
is only necessary to output the final list of prime numbers and not to show
each step in the calculation.

This is What I have done
and is working.
public class InitArray
{
public static void main(String args[])
{
if(args.length != 3)
System.out.println("Please re-enter the entire command, including\n" + "array size, initial value and increment.");
else
{
int arrayLength = Integer.parseInt(args[0]);
int array[] = new int[arrayLength];

int initialValue = Integer.parseInt(args[1]);
int increment = Integer.parseInt(args[2]);

for(int counter = 0;counter < array.length;counter++)
array[counter] = initialValue + increment * (counter + 2);
System.out.printf("%s%8s\n", "Index", "Value");

for(int counter = 0;counter < array.length;counter++)
System.out.printf("%5d%8d\n", counter,array[counter]);
}
}
}
My problem is I don't know how to add the number beacuse I am entering the number I wish and is not suppose to be like that I have to declare a list of prime numbers ,I don't know how to dao that and also I don't undrstand the fith statement about the squaroot I don't know how to do that please help me.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingJava Development > Prime numbers using arrays


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway
Stay green...Green IT