【发布时间】:2015-04-15 02:41:30
【问题描述】:
我最近在业余时间开始学习 java。所以为了练习,我正在制作一个程序,它需要温度(摄氏度或华氏度)并将其转换为相反的温度。我已经导入了键盘扫描器。
int temp;
String opposite, type;
double product;
System.out.print("Please enter a temperature: ");
temp = keyboard.nextInt();
System.out.println("Was that in Celsius or Fahrenheit?");
System.out.print("(Enter 'C' for Celsius and 'F' for Fahrenheit) ");
type = keyboard.nextLine();
if (type == "C") // Only irrelevant temp conversion code left so I'm leaving it out
我是 String 和 nextLine 的新手,程序只是跳过了输入 C 或 F 的用户输入部分。有人能解释一下我能做些什么来解决这个问题吗?
谢谢!
【问题讨论】:
标签: java