Main
public class Main{
public static void main(String[]args){
Prima p = new Prima(2,10);
System.out.println(p.jumlah());
}
}
Prima
public class Prima{
private int min;
private int max;
public Prima(int min, int max){
this.min = min;
this.max = max;
}
public int jumlah(){
int jumlah =0;
int a;
for(int i = this.min+1; i<this.max; i++){
a=0;
for(int j=1; j<=i; j++){
if(i%j==0){
a = a+1;
}
}
if(a==2){
jumlah=jumlah+i;
}
}
return jumlah;
}
}
0 komentar:
Post a Comment