0

There is no compilation error, however the input string is not showing up. There's just a blank in its place. Am I missing something?

import java.util.Scanner;

public class Solution {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int i = scan.nextInt();
        double d=scan.nextDouble();
        String s=scan.nextLine();
        System.out.println("String: " + s);
        System.out.println("Double: " + d);
        System.out.println("Int: " + i);
    }
}




Sneha
  • 5
  • 1
  • There is a problem combing Scanner#next*() methods with Scanner#nextLine(). I never use Scanner, but rather I take input from a BufferedReader initialized on System.in. – NomadMaker Apr 06 '21 at 19:54
  • @NomadMaker just get used to always initializing your scanner properly: `scanner.useDelimiter("\\R")`, and then just call `.next()` for a line, `.nextInt()` for an int, etc. – rzwitserloot Apr 06 '21 at 20:22
  • @rzwitserloot I've been programming Java since the first beta, and I've never used Scanner. BufferedReader#readLine() has been my favorite when I'm slumming in the console rather than using a gui. – NomadMaker Apr 06 '21 at 21:04
  • @NomadMaker When I started my programming career, it was with QBasic. I don't use that anymore, though :) – rzwitserloot Apr 06 '21 at 22:36

0 Answers0