回 帖 发 新 帖 刷新版面

主题:帮忙分析下什么意思

看不明白这道题目到底什么要求.
请各位帮忙!
谢谢!
The following pseudocode will build an array, a, containing the first n prime numbers: 
Set the first element of a to the lowest prime number (2).
For each odd number, test, starting at 3:
    For each element, p, in a:
        Compute the remainder of test/p.
    If the remainder was non-zero for every p:
        Append test to a.
    If the length of a equals n:
        break
[b]Assignment:[/b]
Create a Java program, Prime.java, to implement this algorithm. The program should accept one command-line argument, the number of primes to generate (n). It should respond by printing the first n prime numbers, followed by a message stating the n-th prime number. If more than 10 prime numbers are requested, the program should print only the first five and the last five, separated by a line displaying an ellipsis ("..."). 
For example: 
$ java Prime 13
   2
   3
   5
   7
   11
   ...
   23
   29
   31
   37
   41
The 13-th prime number is 41.
$
[b]Other requirements: [/b]
•    Your program should generate the entire array of prime numbers before printing any of them, rather than printing them "on the fly". 
•    For n equal to 1, 2, or 3, the output should read "first", "second", or "third" rather than "1-th", "2-th", or "3-th". (Feel free to generalize this to other numbers.) 
•    If no command-line argument is supplied, the program should print a helpful message to the Java error stream, System.err, and exit. 
•    Use int (4-byte) variables throughout the program. 
•    Your program should make no assumption about the maximum number of primes which can be requested. For example, you cannot simply define a as an 8000-element array. 
•    If the command-line argument is less than one, assume that it is equal to one. 


回复列表 (共1个回复)

沙发

Easy program, read twice, three times, you will understand.

[quote]The following pseudocode will build an array, a, containing the first n prime numbers[/quote]

That is all.

All others just some print requirements. Finish this, then worry about those later.

Happy learning and goos luck!

我来回复

您尚未登录,请登录后再回复。点此登录或注册