Why Wont My Java Scanner Take In input?

前端 未结 3 757
南方客
南方客 2021-01-23 05:52
package Lessons;

import java.util.Scanner;

public class Math {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        System.         


        
3条回答
  •  盖世英雄少女心
    2021-01-23 06:11

    Calling s.nextInt() reads the next int, but does not read the new line character after that. So the new line would be read on line 15. If you are sure that every input will be put in a separate line, then you can resolve this problem by putting an extra s.nextLine() before line 15:

    ...
    System.out.print(" Now enter ur operator ");
    s.nextLine();
    String b1 = s.nextLine();
    ...
    

提交回复
热议问题