Posted in Program Java

Program Java Menampilkan Bilangan Prima

Selamat siang bloggers, mari kita belajar menampilkan bilangan prima menggunakan bahasa pemrograman java. Let’s Check It Out

Program Java menampilkan Bilangan Prima 0-100

package javaapplication70;

/**
*
* @author Rifa'atul Mahmudah
*/
public class JavaApplication70 {
/**
* @param args the command line arguments
*/
public static int cekPrima(int bil){
int bagi=3, batas=bil;

if(bil==1)
return 0;
else if((bil==2)||(bil==3))
return 1;
else if(bil%2==0)
return 0;
else{
while(batas>bagi){
if(bil%bagi==0)
return 0;
batas=bil/bagi;
bagi+=2;
}
return 1;
}
}

public static void main(String[] args) {

for(int bilangan=1; bilangan<100;bilangan++){
if(cekPrima(bilangan)==1){
System.out.print(+bilangan+ " ");
}
}
}

}

Output Program

2

Selamat Mencoba Semoga BermanfaatπŸ™‚

 

Author:

Give your best

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s