当我运行我的程序时,出现以下异常:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at eraKevgiri.main(eraKevgiri.java:29)
这段代码有什么问题?
public static void main(String[] args) {
int gSayi = 0;
int kKok = (int) Math.sqrt(gSayi);
boolean[] liste = new boolean[gSayi + 1];
Scanner klavye = new Scanner(System.in);
System.out.println("Sayı Girin:");
gSayi = klavye.nextInt();
for(int i=2; i<=kKok; i++){
System.out.println("" +i);
for(int j=i*i; j<=gSayi; j+=i){
liste[j] = true;
}
}
for(int k=kKok; k<=gSayi; k++){
if(!liste[k]){ //-------> problem in here
System.out.println("" + k);
}
}
klavye.close();
}