0

//Program to display prime numbers between 2 range using command line argument

class prime
{
    public static void main(String args[])
{
    if(args.length!=2)
    {
        System.out.println("Enter both starting & ending limit, only 2");
        System.exit(0);
    }
int num=Integer.parseInt(args[0]);
int num1=Integer.parseInt(args[0]);
int count;
if (count<=1)
{
    System.out.println("Prime numbers starts from 2");
    System.exit(0);
}
for(int i=num; i<num1; i++)
{
    count=0;
    for(int j=2;j<=i/2;j++)
    {
        count++;
        break;
    }
if(count==0)
System.out.print(i);
}
}
}

This is the error:

javac prime.java
prime.java:15: error: variable count might not have been initialized
if (count<=1)

But I have initialised it already. Any help? I am new to SO

Rahul Gohrani
  • 37
  • 1
  • 1
  • 3
  • Not that it solves this problem, but are you sure that this is right `int num=Integer.parseInt(args[0]); int num1=Integer.parseInt(args[0]);`? – Pshemo Sep 29 '15 at 18:07

1 Answers1

0

you need initialize count variable, something like

int count = 0;

your error message clearly says

: error: variable count might not have been initialized

subash
  • 3,116
  • 3
  • 18
  • 22