Prime visit what is wrong pls check

import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scn=new Scanner(System.in);
int n=scn.nextInt();

	for(int i=0;i<n;i++)
	{
		int a=scn.nextInt();
		int b=scn.nextInt();
		primevisit(a,b);
	}

}
public static void primevisit(int a,int b){
	int count=0;
	for(int i=a+1;i<b;i++)
	{
		for(div=2;div<b-1;div++)
		{    
			if(i%div!=0)
			{count++}

			
		}
	}
	System.out.println(count);
}

}

what is wrong incode

it shows runtime error

You are getting a runtime error because you have not put a semi-colon here.

But apart from that, your logic also isn’t completely correct. You have to count the number of prime numbers between a and b, where a and b are included.

import java.util.Scanner; public class Main { public static void main(String args[]) { Scanner scn=new Scanner(System.in); int n=scn.nextInt(); for(int i=0;i<n;i++) { int a=scn.nextInt(); int b=scn.nextInt(); primevisit(a,b); } } public static void primevisit(int a,int b){ int count=0; for(int i=a;i<=b;i++) { for(int div=2;div<b-1;div++) { if(i%div!=0) {count++;} } } System.out.println(count); } }

i make correction,still giving error

import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner scn=new Scanner(System.in);
int n=scn.nextInt();

	for(int i=0;i<n;i++)
	{
		int a=scn.nextInt();
		int b=scn.nextInt();
		primevisit(a,b);
	}

}
public static void primevisit(int a,int b){
	int count=0;
	for(int i=a;i<=b;i++)
	{
		for(int div=2;div<b;div++)
		{    
			if(i%div!=0)
			{count++;}

			
		}
	}
	System.out.println(count);
}

}

still showing error

That is because your logic is still incorrect. This ‘for’ loop will not go uptil ‘b’. Since you are checking whether ‘i’ is prime or not, it should go till sqrt(i). And you are not counting the number of prime numbers, but you are incrementing count everytime a number is not divisible by div. What you have to do is, outside this loop you need to check if count is 0, and if it is, then increase count_prime(a variable for number of prime numbers) by 1.

For clarity and better understanding, I suggest you write a separate function checkPrime to check if a number is prime or not, try it for different test cases and then call it in your primevisit function.

what to return inside the loop
pls modify the code

written* …………………………….

Just do one thing, write a separate function that takes one number as input and return true if the number is prime and false if the number is not prime. After that I will help you with what to do further. You will also have to optimize this as this approach will give TLE, but that we’ll do at a later stage

hey, there is my corrected code
import java.util.Scanner;
public class Main {
static Scanner scn=new Scanner(System.in);
public static void main(String args[]) {
int N=scn.nextInt();
for(int i=0;i<N;i++)
{

    checkprime();
	}
    
}
public static void checkprime()
{  int i,x;
   int l=scn.nextInt();
    int u=scn.nextInt();
   int count=0;
   for( x=l;x<=u;x++)
   {  
    for(i=2;i<x;i++)
    {
        if(x%i==0)
        {
            break;
        }
    }
   
    if(i==x)
    {   
        count++;
    }   
   }   
        System.out.println(count);
   
}

}

it not get submitted, 1 test case of timelimit giving problem

now it showing exception in thread main mismatch input

input mismatch exception will come if you’ve not given input or your input format is wrong. I have made a few corrections to your code and replied on chat, you can check there

using seive of eratonthenes method runtime error

I have sent corrected code on chat, check that and if there’s anything you don’t understand then let me know

Arrays.fill(primes, true); what it means

and tell me what was wrong in my code