Advertisement
Guest User

Untitled

a guest
Sep 19th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.41 KB | None | 0 0
  1. public class Loops4 {
  2.  
  3.     public static void main(String[] args) {
  4.         int x, z;
  5.         boolean prime = false;
  6.         for (x = 2; x <= 100; x += 1 ) {
  7.             prime = true;
  8.             for (z = 2; z < Math.floor(Math.sqrt(x)); z+=1) { //checks if the number is divisible by anything
  9.                 if (x % z == 0) {
  10.                     prime = false;
  11.                 }
  12.             }
  13.             if (prime == true) {
  14.                 System.out.println(x); //if x is prime, print it
  15.             }
  16.         }
  17.  
  18.     }
  19.  
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement