Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Prima {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- System.out.println("Masukkan angka");
- Scanner sc = new Scanner(System.in);
- int n = sc.nextInt();
- for (int i = 1; i <= n; i++) {
- Boolean prima = isPrime(i);
- if(prima) {
- System.out.print(i+" ");
- }
- }
- }
- static boolean isPrime(int n) {
- int jumlah = 0;
- for(int i = 1; i <= n; i++) {
- if(n%i == 0){
- jumlah++;
- }
- }
- if(jumlah == 2 ) {
- return true;
- }else {
- return false;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement