Berikut Flowchart nya
Berikut coding nya
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package prima;
/**
*
* @author yellow
*/
import javax.swing.JOptionPane;
public class prima {
private static int i;
static boolean prima(int n) {
boolean b = true;
i=0;
if(n < 1) b = false;
if(n > 1) {
for(int i = 2; i <=(n / 2); i++) {
if(n % i == 0) {
b = false;
break;
}
}
}
return b;
}
public static void main(String[] args) {
String numStr = JOptionPane.showInputDialog("Masukkan bilang integer:");
int numInt = Integer.parseInt(numStr);
String cek = " Benar, Bilangan Ganjil dan Prima";
if(!prima(numInt)) cek = "Bukan Prima dan Bukan Ganjil";
JOptionPane.showMessageDialog(null, numStr + "\n" + cek);
}
}
Tidak ada komentar:
Posting Komentar