Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.
public class PrimeTest {
public static void main(String[] args) {
int number =2;
int numberOfPrimes=6;
// Repeatedly find prime numbers
System.out.println(" no. % div. == 0 prime");
System.out.println("----------------------------");
while( number < numberOfPrimes) {
if(isPrime(number)){
System.out.println("C "+number);
}
number++;
}
}
public static boolean isPrime(int number) {
for (int divisor = 2; divisor <= number/2; divisor++) {
System.out.println("A "+number+" % "+divisor +" == "
+ (number % divisor)+" "+((number % divisor==0)? "":number));
if (number % divisor ==0) {
return false;
};
}
return true;
}
}
public class primes {
public static void main(String[] args) {
int number =2;
int numberOfPrimes=6;
System.out.println(" no. % div. == 0 prime");
System.out.println("----------------------------");
while( number < numberOfPrimes) {
if(isPrime(number)){
System.out.println( number );
}
number++;
}
}
public static boolean isPrime(int number) {
for (int divisor = 2; divisor <= number/2; divisor++) {
if (number % divisor ==0) {
return false;
};
}
return true;
}
}
no. % div. == 0 prime
----------------------------
2
3
5
public static boolean isPrime(int number) {
if(number == 2 || number == 3)return true;
for (int divisor = 2; divisor <= number/2; divisor++) {
// System.out.println("A "+number+" % "+divisor +" == "
// + (number % divisor)+" "+((number % divisor==0)? "":number));
if (number % divisor ==0) {
return false;
};
}
return true;
}
[2, 3, 5, 7, 11, 13]
import java.util.ArrayList;
public class PrimeTest {
public static void main(String[] args) {
int number =2;
int numberOfPrimes=10;
ArrayList<Integer> ar = new ArrayList<Integer>();
int numb = 2;
while(true){
if(isPrime(numb)){
ar.add(numb); if(ar.size() == numberOfPrimes)break;
}
numb++ ;
}
// System.out.println(ar);
for(Integer ii : ar){
System.out.println("C " + ii );
}
// Repeatedly find prime numbers
// System.out.println(" no. % div. == 0 prime");
// System.out.println("----------------------------");
while( number < numberOfPrimes) {
if(isPrime(number)){
// System.out.println("C "+number);
}
number++;
}
}
public static boolean isPrime(int number) {
if(number == 2 || number == 3)return true;
for (int divisor = 2; divisor <= number/2; divisor++) {
// System.out.println("A "+number+" % "+divisor +" == "
// + (number % divisor)+" "+((number % divisor==0)? "":number));
if (number % divisor ==0) {
return false;
};
}
return true;
}
}
C 2
C 3
C 5
C 7
C 11
C 13
C 17
C 19
C 23
C 29
import java.util.Arrays;
public class Eratosthenes
{
int max;
int primes[];
public static void main(String args[])
{
Eratosthenes erat = new Eratosthenes(100);
erat.find_primes();
System.out.println(Arrays.toString(erat.primes));
}
public Eratosthenes(int max)
{
this.max = max;
}
public void find_primes()
{
int i,j,k, divisor, offset;
double sqrt = Math.sqrt(max)+1;
int tmp[];
if(max > 100)
{
primes = new int[max/2];
}
else
{
primes = new int[max];
}
primes[0] = 2;
primes[1] = 3;
for(i=2,j=5; j < max ; j+=2)
{
if(j % 3 != 0)
{
primes[i++] = j;
}
}
for(i=2, divisor=5, offset = primes.length; divisor < sqrt ; )
{
j = i*i;
tmp = new int[offset];
offset = j;
/*
* Copy the numbers that have already been sieved to a new array.
*/
System.arraycopy(primes,0,tmp,0,j);
while( j < tmp.length)
{
k = primes[j++];
if(k==0)
{
/*
* The array may contain some zeros at the end. It's too much
* trouble to calculate the exact size for the array. Easier
* to pad with zeros
*/
break;
}
if(k % divisor != 0)
{
tmp[offset++] = k;
}
}
primes = null;
primes = tmp;
tmp = null;
divisor = primes[i++];
}
}
}
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 49, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 0, 0]
If you are experiencing a similar issue, please ask a related question
Join the community of 500,000 technology professionals and ask your questions.