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

后端 未结 7 628
耶瑟儿~
耶瑟儿~ 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

    Never use Scanner#nextLine after Scanner#nextInt. Whenever you hit enter button after Scanner#nextInt than it will skip the Scanner#nextLine command. So, Change from

     int temp = keyboard.nextInt();
    

    to

     int temp = Integer.parseInt(keyboard.nextLine());
    

提交回复
热议问题