PrimeNumber - S/while loop to repeatedly find primes...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
/**Trinity Martin *Week 03 *Lab 3.1 Prime Numbers *it 218 */ * public class PrimeNumber { public static void main(String[] args) { final int NUMBER_OF_PRIMES = 1000; //Number of primes to display final int NUMBER_OF_PRIMES_PER_LINE = 10; // Display this may per line int count = 0; //counts the number of primes int number = 2; //number tested for primeness System.out.println("The first 1000 prime numbers are \n");
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: S //while loop to repeatedly find primes / while (count < NUMBER_OF_PRIMES) { boolean isPrime = true; for (int divisor = 2; divisor <= (number /2); divisor++) { if (number % divisor == 0) { isPrime = false; break; } } if (isPrime) { count++; c if (count % NUMBER_OF_PRIMES_PER_LINE == 0) { System.out.println(number); } else System.out.print(number + " "); number++; } } } }...
View Full Document

This note was uploaded on 07/26/2011 for the course IT 218 taught by Professor Accampo,e during the Spring '11 term at ITT Tech Pittsburgh.

Ask a homework question - tutors are online