How to take the startiing range and ending range

I got the approach of solving this problem using sieve of Eratosthenes
but I am not getting how to apply the starting range and the ending range to the same.

Make a cumulative count array of the prime sieve and then answer is count[b] - count [a]

I have got the range
but the thing is I am still getting all the test cases wrong

Please post your code

Scanner sc=new Scanner(System.in);
int a=0;
int b=11;
int n=b-a;
int count=0;

if(a>1)
{
	
	int[] arr=new int[n+1];

for(int i=0;i<arr.length;i++)
{
	
	
		
	
	for(int j=i;j<=i;j++)
	{
		arr[j]=a;
		a++;
	}
}
for(int i=0;i<arr.length;i++)
{
	System.out.println(arr[i]);
}
for(int i=0;i<arr.length;i++)
{
	boolean flag=true;
	for(int divisor=2;divisor<arr[i];divisor++)
	{
		if(arr[i]%divisor==0)
		{
			flag=false;
		}
	}
	if(flag==true)
	{
		count++;
	
	}

}
System.out.println(count);

}

else if(a==0)
{
int[] arr=new int[n];
a=a+2;
for(int i=0;i<arr.length;i++)
{
for(int j=i;j<=i;j++)
{
arr[j]=a;
a++;
}
}
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}
for(int i=0;i<arr.length;i++)
{
boolean flag=true;
for(int divisor=2;divisor<arr[i];divisor++)
{
if(arr[i]%divisor==0)
{
flag=false;

	 }
 }
 if(flag==true)
 {
	 count++;
 }

}
System.out.println(count);
}
else
{
int[] arr=new int[n];
a=a+1;
for(int i=0;i<arr.length;i++)
{
for(int j=i;j<=i;j++)
{
arr[j]=a;
a++;
}
}
for(int i=0;i<arr.length;i++)
{
System.out.println(arr[i]);
}
for(int i=0;i<arr.length;i++)
{
boolean flag=true;
for(int divisor=2;divisor<arr[i];divisor++)
{
if(arr[i]%divisor==0)
{
flag=false;

		 }
	 }
	 if(flag==true)
	 {
		 count++;
	 }
 }
 System.out.println(count);

}
}
}

I have even tried it with sieve of Eratosthenes but its showing me an error

What exactly have you done in this code ? Why are you printing the initial array ?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.