OliverE Power member. Joined Mar 19, 2011 Posts 3,687 Reacts 0 Reputation 0 Credits 5 Nov 21, 2011 #1 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
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
Factor8™ Active Member Joined Mar 19, 2011 Posts 1,516 Reacts 0 Reputation 0 Credits 0 Nov 21, 2011 #2 RE: Prime Number? I have a little more than 10 posts. Does return true/false actually show true and false?
RE: Prime Number? I have a little more than 10 posts. Does return true/false actually show true and false?
OliverE Power member. Joined Mar 19, 2011 Posts 3,687 Reacts 0 Reputation 0 Credits 5 Nov 21, 2011 #3 RE: Prime Number? There you go, updated OP. That will display true or false depending on the value of i.
RE: Prime Number? There you go, updated OP. That will display true or false depending on the value of i.