Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
PE #3
//Title of this code //'main' method must be in a class 'Rextester'. //Compiler version 1.8.0_45 import java.util.*; import java.lang.*; class Rextester { public static void main(String args[]) { BigInteger spork = 600851475143; boolean potato = isPrime(spork); System.out.println(potato); } public static boolean isPrime(BigInteger number) { String numStr = ""+number; int numSum =0; int sqrtNum = (int)Math.sqrt((double)(number)); int bigFac = -1; for(int i =0; i<numStr.length(); i++) { numSum += Integer.parseInt(numStr.substring(i, i+1)); } System.out.println("Sum: "+numSum); if (numSum%3==0) { return false; } if ((number%2==0)&&(number!=2)) { return false; } if ((numStr.substring(numStr.length()-1, numStr.length()))=="5") { return false; } for(int i=7; i<sqrtNum; i+=2) { if(number%i==0) { System.out.println("Factor: "+i); return false; } } return true; } }
run
|
edit
|
history
|
help
0
your age
Happy Numbers in Java
word Ladder
Increment Operator
strstr() function / indexOf() function
Majors
continue
JAVA regex for only allow numbers
Dollar. java
Fibonacci 2