0

I'm trying to read multiple inputs (Variables) of different datatypes. Here is my code:

    Scanner scan = new Scanner(System.in);
    int i = scan.nextInt();
    double d = scan.nextDouble();
    // String s = scan.nextLine(); 
    String s="";
    s+=scan.nextLine();
    scan.close();

    // Write your code here.

    System.out.println("String: " + s);
    System.out.println("Double: " + d);
    System.out.println("Int: " + i);

The problem is I'm able to read int and double type variables but I'm not able to read String type Variable.

Here according to the code it prints only values of i and d that is int and double type and does not print s that is String can anyone explain to me why?

Vogel612
  • 5,474
  • 5
  • 47
  • 69
rahul uday
  • 131
  • 1
  • 9
  • Try putting a `scan.nextLine()` before you're reading the string. Put another one between the reading of the integer and the double. What does that tell you? – Vogel612 Aug 10 '18 at 19:34
  • @YCF_L I tried it and i have commented it .Does not work any other suggestions? – rahul uday Aug 10 '18 at 20:03
  • 1
    I'm not sure It work with me did you tried this https://ideone.com/YuaTG6 – YCF_L Aug 10 '18 at 20:06

0 Answers0