Guest User

Untitled

a guest
Dec 18th, 2017
593
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. public class C10E6 {
  2.  
  3. public static void main(String[] args) {
  4.  
  5. StackOfIntegers stack = new StackOfIntegers();
  6.  
  7. for (int i = 2; i < 120; i++) {
  8. if (isPrime(i))
  9. stack.push(i);
  10. }
  11.  
  12. System.out.println(
  13. "\nAll the prime numbers less than 120 in decreasing order:");
  14. while (!stack.empty()) {
  15. System.out.print(stack.pop() + " ");
  16. }
  17. System.out.println();
  18. }
  19.  
  20. public static boolean isPrime(int n) {
  21. for (int d = 2; d <= n / 2; d++) {
  22. if (n % d == 0)
  23. return false;
  24. }
  25. return true;
  26. }
  27. }
Add Comment
Please, Sign In to add comment