Program Java : Menampilkan Bilangan Prima

~ Menampilkan Bilangan Prima dengan Batas Atas dan Bawah ~

***********

Coding :

/*
* To change this template, choose Tools | Template
* and open the template in the editor.
*/
package bilanganprima;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
*
* @author Ayu
*/
public class Bilanganprima {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
System.out.println(“PROGRAM MENAMPILKAN BILANGAN PRIMA”);
BufferedReader dataln = new BufferedReader(new InputStreamReader(System.in));

int batasatas;
int batasbawah;
int hitung;

try{
System.out.println(“Masukkan Nilai Batas Atas : “);
batasatas = Integer.parseInt(dataln.readLine());

System.out.println(“Masukkan Nilai Batas Bawah : “);
batasbawah = Integer.parseInt(dataln.readLine());

System.out.println(“_ _ _ _ _ _ _ _ _ _ _ _”);
System.out.println(“Bilangan Prima”);
System.out.println(“_ _ _ _ _ _ _ _ _ _ _ _”);

for(int i=batasatas;i<=batasbawah;i++){
hitung=0;
for(int a=1;a<=i;a++){
if(i%a==0){
hitung+=1;
}
}

if(hitung==2){
System.out.println(i);
}
}

}catch(IOException e){
System.out.println(“Error!”);
}
}
}

the first pict :

the second pict :

the last pict :

NetBeans software

Advertisements

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