Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Loops4 {
- public static void main(String[] args) {
- int x, z;
- boolean prime = false;
- for (x = 2; x <= 100; x += 1 ) {
- prime = true;
- for (z = 2; z < Math.floor(Math.sqrt(x)); z+=1) { //checks if the number is divisible by anything
- if (x % z == 0) {
- prime = false;
- }
- }
- if (prime == true) {
- System.out.println(x); //if x is prime, print it
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement