Hi guys
I started to learn java and have a little problem\. When I try to compile my little program it says :
assgn2.java:40: variable overnight might not have been initialized
System.out.println(overnight);
How is that?
The code:
import java.io.*;
public class assgn2
{
public static void main(String[] args) throws IOException
{
BufferedReader value=new BufferedReader(new InputStreamReader(System.in));
String item,itemPrice,ans;
double price,overnight;
int answer;
System.out.println("\n\t*********************************************");
System.out.println("\n\t\tSam and Ella's Delicatessen ");
System.out.println("\n\t*********************************************");
System.out.print(" What is the nome of the item: ");
item=value.readLine();
System.out.print(" What is the price of an item: ");
itemPrice=value.readLine();
price=Double.parseDouble(itemPrice);
do
{
System.out.print("Overnight delivery (0=no, 1=yes) : ");
ans=value.readLine();
answer=Integer.parseInt(ans);
if (answer==0)
{
overnight=5.00;
break;
}
else if (answer==1)
{
overnight=0.00;
break;
}
else
System.out.println(" You entered wrong value. Try again: \n");
}while((answer!=1)||(answer!=0));
System.out.println(overnight);
}
}
thx