Pangil_aku_Andi

Don't Give Up in Life …

Mencari Bilangan Prima


import javax.swing.JOptionPane;
public class bilanganPrima {
public static void main(String[] args) {
String numString;
int numInt;
int i;
int jum=0;
numString = JOptionPane.showInputDialog(“Masukkan bilangan integer: “);
numInt = Integer.parseInt(numString);

for(i=1;i<=numInt;i++){
if (numInt % i == 0) {
jum = jum + 1;
}
}
if(jum==2 && numInt != 1){
JOptionPane.showMessageDialog(null,”Bilangan Prima”,”Pesan”,1);
}
else {
JOptionPane.showMessageDialog(null,”Bukan Bilangan Prima”,”Pesan”,0);
}
}
}

save dengan “bilanganPrima.java”

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

%d bloggers like this: