public class LocInit {
public static void main(
String[] args) {
int weight = 10;
int theprice;
if(weight < 10) theprice = 100;<br /> if(weight > 50) theprice = 5000;
if(weight >= 10) theprice = weight*10;
System.out.println("The price is:" + theprice);
}
}
When i compile the above code iam getting a compilation error as:
LocInit.java:10: Variable theprice may not have been initialized.
System.out.println("The price is:" + theprice);
^
1 error
but the price value is already initialized it in lines 6,7 ,8.Why aim getting a compilation error.
Iam little bit confused about it.Could anybody please help me.