黑马程序员技术交流社区

标题: 刚学java,哪个大神教教这题怎么做 [打印本页]

作者: Change.+    时间: 2015-10-30 23:28
标题: 刚学java,哪个大神教教这题怎么做
  1. The method generatePrimes places the first set of primes in an array. Add the statements to the morePrimes method that fill the remaining locations in the array with the next primes. For each value, divide the value by all of the primes in the array; if the value is not evenly divisible by one of the primes, then that value is a prime and is to be added to the array in the next available location. Do not use any temporary arrays. This question does not require the use of the Sieve of Eratosthenes. The method is to terminate when all of the locations in the array are filled with prime values. Print the values in the array to System.out when the loop terminates.


  2. import java.util.Arrays;

  3. public class primeNumber
  4. {
  5. public static void main(String[] parms)
  6. {
  7. process();
  8. System.out.println("\nProgram completed normally.");
  9. }

  10. public static void process()
  11. {
  12. int[] primes;
  13. int numPrimes;

  14. primes = new int[25];
  15. numPrimes = generatePrimes(primes);
  16. System.out.println(Arrays.toString(primes));

  17. morePrimes(primes, numPrimes);
  18. System.out.println(Arrays.toString(primes));
  19. }

  20. public static int generatePrimes(int[] primes)
  21. {
  22. int[] initialPrimes = new int[]{2, 3, 5, 7, 11, 13, 17};
  23. int count;

  24. System.arraycopy(initialPrimes,0,primes,0,initialPrimes.length);

  25. return initialPrimes.length;
  26. }

  27. public static void morePrimes(int[] primes, int numPrimes)
  28. {
  29. int count;
  30. int value;
  31. boolean done;

  32. }
  33. }
复制代码





欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) 黑马程序员IT技术论坛 X3.2