Advertisement
Krefeld187

Untitled

Oct 10th, 2020
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.57 KB | None | 0 0
  1. package Problem3;
  2.  
  3. public class LargestPrimeFaktor
  4. {
  5. static long s = 114;
  6. static long primefa = 0;
  7.  
  8. public static void main(String[] args)
  9. {
  10. factor();
  11. System.out.print(primefa);
  12. }
  13.  
  14. public static void factor()
  15. {
  16. for(long i = s; i >=1 ; --i)
  17. {
  18.  
  19. if(s % i == 0 && isPrime(i) == true)
  20. {
  21. primefa = i;
  22. break;
  23. }
  24. }
  25. }
  26.  
  27. public static boolean isPrime(long n)
  28. {
  29. if (n <= 1)
  30. return false;
  31.  
  32. for (int i = 2; i < Math.sqrt(n); i++)
  33. {
  34. if (n % i == 0)
  35. return false;
  36. }
  37. return true;
  38. }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement