Menampilkan bilangan prima dengan netbeans
package pelatihan;
public class prima {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
char tanda[] = new char[101];
for (int i = 2; i <= 100; i++) {
if (tanda[i] != '*') {
System.out.println(i+"");
for (int j = i * 2; j <= 100; j+=i) {
tanda[j]='*';
}
}
}
}
}
public class prima {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
char tanda[] = new char[101];
for (int i = 2; i <= 100; i++) {
if (tanda[i] != '*') {
System.out.println(i+"");
for (int j = i * 2; j <= 100; j+=i) {
tanda[j]='*';
}
}
}
}
}
Komentar
Posting Komentar