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

后端 未结 7 588
耶瑟儿~
耶瑟儿~ 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 04:00

    Call

      keyboard.nextLine();
    

    After

      temp = keyboard.nextInt();
    

    Because nextInt() doesn't consume the \n character.

    Also, compare Strings with .equals(); not ==

    if(type.equals("C"));
    
    0 讨论(0)
提交回复
热议问题