Created
May 1, 2020 20:01
-
-
Save alvareztech/f2dd70b6bb73ff7df64ef89ce5b06585 to your computer and use it in GitHub Desktop.
Prime Numbers with just a while in Java.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
public class Main { | |
public static void main(String[] args) { | |
Scanner e = new Scanner(System.in); | |
int n = e.nextInt(); | |
int c = 1; | |
int p = 2; | |
int divisor = 2; | |
while (c <= n) { | |
if (p % divisor == 0) { | |
if (p == divisor) { | |
System.out.print(p + ", "); | |
c++; | |
} | |
divisor = 2; | |
p++; | |
} else { | |
divisor++; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment