Advertisement
Guest User

Untitled

a guest
May 16th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. public class optimusprime {
  2.  
  3.  
  4. public static void main(String[] args) {
  5.  
  6.  
  7.  
  8. System.out.print(" Prime Numbers"); // table head
  9.  
  10.  
  11. int n = 100;
  12. for(int i = 2; i <= n; i++) { // lines 12 -22 sets up the logic for prime numbers
  13.  
  14.  
  15.  
  16. int count = 0;
  17.  
  18. for(int j = 2;j < i;j++) {
  19.  
  20. if (i % j == 0) {
  21. count++;
  22. }
  23. }
  24. if(count==0) {
  25. System.out.print(" ");
  26. System.out.print( " | "); // lines 25-30 was my poor attempt at creating a table
  27. if (i % 10==0)
  28. System.out.print("\n");
  29. System.out.print(i + " ");
  30.  
  31.  
  32. }
  33. }
  34. }
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement