2
import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
            Scanner sc=new Scanner(System.in);
            int x=sc.nextInt();
            double y=sc.nextDouble();
            sc.nextLine();
            String s=sc.nextLine();


            System.out.println("String: "+s);
            System.out.println("Double: "+y);
            System.out.println("Int: "+x);
    }
}

the 's' variable could not take input of multiple words if I did not use sc.nextLine() before that. Can someone explain this?

Vishwa Ratna
  • 4,468
  • 4
  • 24
  • 46
KK_2187
  • 39
  • 1
  • 3
    Does this answer your question? [Scanner is skipping nextLine() after using next() or nextFoo()?](https://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-or-nextfoo) – Amongalen May 20 '20 at 08:47

0 Answers0