package primesieve1;
import java.io.InputStreamReader;
import java.util.Scanner;
public class Primesieve1 {
public boolean[] sieveOfEratosthenes(int max){
boolean[] primeno; //defaults to false
primeno = new boolean[max];
for(int i=2; i<max; i++ ){primeno[i]=true;}
for(int i=2; i<Math.sqrt(max);i++){
if(primeno[i] == true){
//all multiples of i*i, except i, are not primeno
for(int j = i + i; j<max; j=j+i){
primeno[j]=false;
}
}
}
return primeno;
}
public void printTrue(boolean[] arr){
for(int i=0; i<arr.length; i++){
if(arr[i]==true){
System.out.print(i + ", ");
}
}
}
public static void main(String[] args) {
System.out.println("enter limit");
Scanner sc = new Scanner(new InputStreamReader(System.in));
int a = sc.nextInt();
boolean a1[];
Primesieve1 obj = new Primesieve1();
a1 = obj.sieveOfEratosthenes(a);
obj.printTrue(a1);
}
}
このエラーを出すと、java.lang.OutOfMemoryError: Java heap space の理由がわかりませんでした