Dhana,
In
java all local variables need to be initialized before any attempt is made to use them. In the first two if statements, you are checking with true conditions, which compiler can easily check during the compilation process. So, your program will compile cleanly if you remove the variable K from code. Since, you included K, compiler cannot check whether it is already initialized above, even though you are conditionally initializing K. Hope this helps..
Regards,
Rama