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

前端 未结 12 1397
灰色年华
灰色年华 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:33

    use a temporary scan.nextLine(); this will consume the \n character

提交回复
热议问题