public class proj22
{
public static void main(String[] args)
{ float degreef, degreec, degree;
string cel = "c";
string far = "f";
string unit;
System.out.println("Enter a temperture:");
scanner keyboard = new Scanner (System.in);
degree = keyboard.nextFloat();
System.out.println("Enter a c to designate Celsius, or an f to designate..");
unit = keyboard.next();
if (unit.equalsIgnoreCase(cel)||unit.equalsIgnoreCase(far))
{
if (unit.equalsIgnoreCase(cel))
{
degreec = 5*(degreef-32)/9;
System.out.println("The degree you entered in Celsius is" +
System.out.println("The degree you entered in Fahrenheit" +
}
else
degreef = degree;
degreef = (9*(degreec/5)+32);
System.out.println("The degree you entered in Fahrenheit" +
degreec + "C");
else
System.out.println("Error: incorrect letter usage.");
}
}
}
此代码正常运行,但在第 27 行编译时出现错误,说明:
"proj22.java:27: error: 'else' without 'if'
else
^
1 error"
我能做些什么来解决这个问题?