fork download
  1. class Go {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. long myNumber = 600L;
  6. System.out.print(getLargestPrimeFactor(myNumber));
  7.  
  8. }
  9. public static long getLargestPrimeFactor(long inNum) {
  10. int i; // define i here to remain in returnable scope
  11. for (i = 1; inNum > 1; i++) { // start at 2 (first prime) and loop until inNum == 1
  12. while (inNum % i == 0) { // if inNum evenly divides by i
  13. inNum /= i; // divide inNum by i until it is no longer divisible
  14. } // Note, (inNum % i == 0) === true only when
  15. } // i is a prime number due to algorithm structure
  16. return i-1; // return i-1, -1 because of post loop incrementation
  17. }
  18. }
  19.  
Runtime error #stdin #stdout 4.98s 245632KB
stdin
Standard input is empty
stdout
Standard output is empty