answersLogoWhite

0

private static boolean IsPrime(int Number)

{

int maxchk = (int) Math.ceil( Math.sqrt(Number) ); //makes it faster because we check less

boolean isit = true;

for (int i=2; i<=maxchk; i++)

{

if (Number % i ==0)

isit=false;

}

return isit;

}

Simply call this from inside a for loop, EG

for (int i=3; i<=N; i++)

isPrime(i)

User Avatar

Wiki User

15y ago

What else can I help you with?

Related Questions

Write a java program to display the number is prime or not?

Simply use a for loop (i) that runs from 2 to N-1. Checking if N % i 0 then its a prime number.


How do you write a java program to check a number is twisted prime or not?

To write a Java program to check if a number is a twisted prime or not, you first need to create a function that checks if the number is prime. You can do this by iterating from 2 to the square root of the number and checking if the number is divisible by any of these values. Once you have verified that the number is prime, you can then check if the number remains prime after twisting its digits (reversing the number and checking if the reversed number is also prime). If both conditions are met, then the number is a twisted prime.


Suppose you are given a number n and are told that 1 and the number n divide into n Does that mean n is prime?

No. All integers are divisible by 1 and themselves. Prime numbers are only divisible by 1 and themselves. Since you were not told that only 1 and n divide into n, you do not know if it is prime. Also, if n = 1, it is neither a prime number nor a composite number.


Why is a number 6 times n - 1 a prime number or a product of a number 6 times m - 1?

Either it is a prime or put m = n! Is that it?


How can you check whether a number is prime or not by a C program using functions?

#include&lt;iostream.h&gt; #include&lt;conio.h&gt; void prime(int n) { clrscr(); int num; cout&lt;&lt;"enter the numbers"&lt;&lt;endl; cin&gt;&gt;num; prime(num); getch(); } void prime(int n) { int prime=1,i; for(i=2;i&lt;=n/2;i++) if(n%i==1) prime=0; if(prime==1) cout&lt;&lt;"the number"&lt;&lt;n&gt;&gt;"is prime"; else cout&lt;&lt;"the number"&lt;&lt;n&lt;&lt;"is not prime"; }


Is there an infinite number of prime number?

Yes. To prove this, we must first assume the answer to be no. If there are a finite number of primes, there must be a largest prime. We'll call this prime number n. n! is n*(n-1)*(n-2)*...*3*2*1. n!, therefore, is divisible by all numbers smaller than or equal to n. It follows, then that n!+1 is divisible by none of them, except for 1. There are two possibilities: n!+1 is divisible by prime numbers between n and n!, or it is itself prime. Either way, we have proved that there are prime numbers greater than n, contradicting our initial assumption that primes are finite, proving that the number of primes is infinite.


How to write a java program that determines the number of prime numbers less than N which is given by the user?

where to start? do you have an algorithm and just want to implement it in java? depends on how big N is, as that will determine which method is most efficient


Is there a infinite number of prime numbers?

Yes. To prove this, we must first assume the answer to be no. If there are a finite number of primes, there must be a largest prime. We'll call this prime number n. n! is n*(n-1)*(n-2)*...*3*2*1. n!, therefore, is divisible by all numbers smaller than or equal to n. It follows, then that n!+1 is divisible by none of them, except for 1. There are two possibilities: n!+1 is divisible by prime numbers between n and n!, or it is itself prime. Either way, we have proved that there are prime numbers greater than n, contradicting our initial assumption that primes are finite, proving that the number of primes is infinite.


Rules of prime numbers?

1) A prime number should have exactly two distinct factors. The factors are 1 and the number itself. 2) If n is a prime number, then, n should not be a factor of (n-1)! Ex: 5 is a prime. 4!=24. 5 is not a factor of 24. 3) Any prime number greater than or equal to 3, can be expressed in a form of 6K+1 or 6k-1 ; where K=0,1,2,3,4,..................


Algorithm to find prime numbers below ten?

Take each number in turn, call it "n", and check whether it has any factors f, such that 1 < f < n. If it doesn't, it is a prime number.Take each number in turn, call it "n", and check whether it has any factors f, such that 1 < f < n. If it doesn't, it is a prime number.Take each number in turn, call it "n", and check whether it has any factors f, such that 1 < f < n. If it doesn't, it is a prime number.Take each number in turn, call it "n", and check whether it has any factors f, such that 1 < f < n. If it doesn't, it is a prime number.


How do you write a program to find whether the given number is prime or not and show output?

#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main() { int n,a=2; clrscr(); printf("\n enter n"); scanf("%d",&amp;n); if(i&lt;=a-1) { if(a%i==0) { printf("\n the given number is not a prime number"); break; } i++; if(a==i) { printf("\n the given number is a prime number"); } getch(); output: enter the value of n:2 the given number is prime number


Prints the 1000th prime number?

// Print prime number series. class prime { void main () { int i = 1; int C = 0; int n = 1; int X = 0; while (X != 1000) { if ( n % i n ) { C = 0; n++ ; i = 0; } } i++ ; } } }