Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Aldidwik_CekPrimaRekursif {
- static int n;
- static int cekPrima(int p){
- if(p==1){
- return 1;
- }else if(n%p==0){
- return 0;
- }else{
- return cekPrima(p-1);
- }
- }
- public static void main(String[] args) {
- Scanner input=new Scanner(System.in);
- System.out.print("Masukkan nilai n : ");
- n=input.nextInt();
- if(n>1){
- int p = cekPrima(n-1);
- if(p==1){
- System.out.println(n + " adalah bilangan prima");
- }else{
- System.out.println(n +" bukan bilangan prima");
- }
- }else{
- System.out.println(n+" bukan bilangan prima");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement