-4

My program is:

import java.io.*;
public class PrimeGenerator
{

 public int isPrime(int x)
 {
    int flag=1;
    for(int i=2;i<x;i++)
        {
            if(x%i==0)
            flag=0;
        }
    return flag;
}

public static void main(String args[])throws IOException
{
    DataInputStream in =new DataInputStream(System.in);
    int t,p1,p2;
    t=Integer.parseInt(in.readLine());
    for(int i=1;i<=t;i++)
    {
        p1=Integer.parseInt(in.readLine());
        p2=Integer.parseInt(in.readLine());
        for(int j=p1;j<=p2;j++)
        {
            if(isPrime(j)==1)
            {
                System.out.println(j);
            }
        }
        System.out.println("\n");
    }
 }
}
dertkw
  • 7,798
  • 5
  • 37
  • 45
Ankur100
  • 1,209
  • 2
  • 8
  • 7

1 Answers1

2

main is a static method while isPrime is declared as an instance method so you cannot simply call it from a static context as the error message suggests.

Since isPrime is context-free, you can simply declare it as static:

public static boolean isPrime(int x)

Also, isPrime should return a boolean, not an int

Jean Logeart
  • 52,687
  • 11
  • 83
  • 118