Is a Number a Prime Number

OliverE

Power member.
Reputation
0
Prime Number?

Finding out if a number is a prime number can be tricky, but heres the code to add to yor java application that will work it out for you.

[java]
public class IsPrime {

public static void main(String[] args)
{
int i = 23;
boolean isprime = true;

for(int k=2; k<i; k++)
{
if(i%k==0)
isprime = false;
}

System.out.println(isprime);
}
}
[/java]

Let me know if your struggling
 
RE: Prime Number?

I have a little more than 10 posts.

Does return true/false actually show true and false?
 
RE: Prime Number?

There you go, updated OP.
That will display true or false depending on the value of i.
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…