Guest User

Untitled

a guest
May 15th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package gregurichassignment9;
  7. import java.util.Arrays;
  8. /**
  9. *
  10. * @author colin
  11. */
  12. public class GregurichAssignment9 {
  13.  
  14. /**
  15. * @param args the command line arguments
  16. */
  17. public static void main(String[] args) {
  18. int[] numbers = new int[501]; //needs to be one more than the max
  19.  
  20. for (int ss=0; ss<numbers.length; ss++){
  21. if (ss <= 1){
  22. numbers[ss] = 1;
  23. }
  24.  
  25. else if (ss > 2 && ss % 2 == 0){
  26. numbers[ss] = 1;
  27. }
  28.  
  29. else if (ss > 3 && ss % 3 == 0){
  30. numbers[ss] = 1;
  31. }
  32.  
  33. else if (ss > 5 && ss % 5 == 0){
  34. numbers[ss] = 1;
  35. }
  36.  
  37. else if (ss > 7 && ss % 7 == 0){
  38. numbers[ss] = 1;
  39. }
  40.  
  41. else if (ss > 11 && ss % 11 == 0){
  42. numbers[ss] = 1;
  43. }
  44.  
  45. else if (ss > 13 && ss % 13 == 0){
  46. numbers[ss] = 1;
  47. }
  48.  
  49. else if(ss > 17 && ss % 17 == 0){
  50. numbers[ss] = 1;
  51. }
  52.  
  53. else if (ss > 19 && ss % 19 == 0){
  54. numbers[ss] = 1;
  55. }
  56.  
  57. }
  58.  
  59. print(numbers);
  60. System.out.println(primeCount(numbers));
  61.  
  62.  
  63.  
  64. }
  65.  
  66. public static int primeCount(int[] array){
  67. int count = 0;
  68. for (int ss = 0; ss<array.length; ss++){
  69. if (array[ss] == 0){
  70. count++;
  71. }
  72. }
  73. return count;
  74. }
  75.  
  76. public static void print(int[] array){
  77. boolean isPrime;
  78. String prime;
  79. for (int ss=0; ss<array.length; ss++){
  80. if (array[ss] == 0){
  81. isPrime = true;
  82. if (isPrime){
  83. prime = "prime";
  84. }
  85. else{
  86. prime = "1";
  87. }
  88. }
  89. else {
  90. prime = "1";
  91. }
  92. System.out.println(ss+ "|" +prime);
  93. }
  94. }
  95.  
  96.  
  97.  
  98. }
Advertisement
Add Comment
Please, Sign In to add comment