Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package gregurichassignment9;
- import java.util.Arrays;
- /**
- *
- * @author colin
- */
- public class GregurichAssignment9 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) {
- int[] numbers = new int[501]; //needs to be one more than the max
- for (int ss=0; ss<numbers.length; ss++){
- if (ss <= 1){
- numbers[ss] = 1;
- }
- else if (ss > 2 && ss % 2 == 0){
- numbers[ss] = 1;
- }
- else if (ss > 3 && ss % 3 == 0){
- numbers[ss] = 1;
- }
- else if (ss > 5 && ss % 5 == 0){
- numbers[ss] = 1;
- }
- else if (ss > 7 && ss % 7 == 0){
- numbers[ss] = 1;
- }
- else if (ss > 11 && ss % 11 == 0){
- numbers[ss] = 1;
- }
- else if (ss > 13 && ss % 13 == 0){
- numbers[ss] = 1;
- }
- else if(ss > 17 && ss % 17 == 0){
- numbers[ss] = 1;
- }
- else if (ss > 19 && ss % 19 == 0){
- numbers[ss] = 1;
- }
- }
- print(numbers);
- System.out.println(primeCount(numbers));
- }
- public static int primeCount(int[] array){
- int count = 0;
- for (int ss = 0; ss<array.length; ss++){
- if (array[ss] == 0){
- count++;
- }
- }
- return count;
- }
- public static void print(int[] array){
- boolean isPrime;
- String prime;
- for (int ss=0; ss<array.length; ss++){
- if (array[ss] == 0){
- isPrime = true;
- if (isPrime){
- prime = "prime";
- }
- else{
- prime = "1";
- }
- }
- else {
- prime = "1";
- }
- System.out.println(ss+ "|" +prime);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment