Why can't I enter a string in Scanner(System.in), when calling nextLine()-method?

前端 未结 12 1378
灰色年华
灰色年华 2020-12-01 10:18

How does this program actually work...?

import java.util.Scanner;

class string
{
    public static void main(String a[]){
        int a;
        String s;
          


        
12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-01 10:40

    Scanner's buffer full when we take a input string through scan.nextLine(); so it skips the input next time . So solution is that we can create a new object of Scanner , the name of the object can be same as previous object......

提交回复
热议问题