【发布时间】:2016-02-03 16:26:53
【问题描述】:
我在编译期间收到错误消息。它期待一个.class。我不认为它应该需要一个。我在编码方面很新,所以请原谅我的无知。我还想要一些关于如何在用户输入 C 或 F 时取消 Case 的指导,以便他们可以输入 c 或 f 而不会收到错误消息。
这是我的代码:
import java.util.Scanner;
import java.util.InputMismatchException;
public class TempCALC
{
public static void main(String[] args)
{
System.out.println("This Program will allow the user to calculate temperature.");
calculateTemp();
}
private static void calculateTemp() {
int F;
int C;
F=0;
C=1;
Scanner input = new Scanner (System.in);
System.out.println("Please enter a F to convert Fahrenheit to Celsius.");
System.out.println("Please enter a C to convert Celsius to Fahrenheit.");
int option = input.nextInt();
if (int=0) {
System.out.println("Please enter a temperature in degrees Fahrenheit.");
ftoc();
} else if (int= 1) {
System.out.println("Please enter a temperature in degrees Celsius.");
ctof();
} else {
System.out.println("ERROR PLEASE ENTER A F OR A C TO PROCEED!");
}
}
private static void ftoc() {
Scanner input = new Scanner(System.in);
Double celsius = input.nextDouble();
System.out.println(celsius + "celsius is" + ((celsius * 9 / 5.0) + 32) + "Fahrenheite");
calculatetemp();
}
private static void ctof() {
Scanner input = new Scanner(System.in);
Double Fahrenheit = input.nextDouble();
System.out.println(Fahrenheit + "Fahrenheit is" + ((Fahrenheit - 32) * (5 / 9.0)) + "Celsius");
calculatetemp();
}
private static void print(String string); {
System.out.println("\n" + string);
}
}
【问题讨论】:
-
看一下toLowerCase(),一会儿我举个例子:tutorialspoint.com/java/java_string_tolowercase.htm
-
在第 23 和 26 行,我得到了预期的 .class。 “if (int=0).class”对我来说毫无意义,所以我必须做错事
标签: java class if-statement while-loop java.util.scanner