User Input not working with keyboard.nextLine() and String (Java)

后端 未结 7 622
耶瑟儿~
耶瑟儿~ 2020-12-22 03:06

I recently started learning java during my spare time. So to practice, I\'m making a program that takes a temperature (Celsius or Fahrenheit) and converts it to the opposite

7条回答
  •  轮回少年
    2020-12-22 03:39

    You could use keyboard.next() instead of nextLine() and as

    user1770155

    mentioned to compare two strings you should use .equals() and what I would do since you're comparing to an upper letter "C" is

     type = keyboard.next().toUpperCase();
    
    
    
    if (type.equals("C"))
    

提交回复
热议问题