Re: why am I getting this error "varible temp1 might not have been initialized"




I did the following and the program compiled but when exectute, it sits
and wait for input.

float temp2=0;
Scanner keyboard2 = new Scanner(System.in);
System.out.println("Enter a float value with 2 decimal position for
a temperature.");
if (keyboard2.hasNextFloat())
temp2 = keyboard2.nextFloat();

String strScale2 ="C";
System.out.println("Enter one character for degree scale (C or
F).");
if (keyboard2.hasNext())
strScale2 = keyboard2.next();

char scale2 = (strScale2.toUpperCase()).charAt(0);

When run, the program sits and wait for input.

.