static void isPrime (int n)
{ int f;
for(int i=2;i<=Math.sqrt(n);i++)
{
if(n % i == 0)
{
f = 1;
}
}
if(n == 1 || f == 1)
{
System.out.println("No");
}
else
System.out.println("Yes");
}
Compilation Error
Compilation Error:
prog.java:42: error: variable f might not have been initialized if(n == 1 || f == 1) ^ 1 error
In .NET integers and other value types always have default values. So in C# variable 'f' would have the default integer value of 0.
I guess Java is different... To get rid of this compile error, simply assign a value to f.
In example: