0

Why string is not accepting the input???

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

20th Dec 2021, 8:10 AM
Sonali Kala
Sonali Kala - avatar
3 Answers
+ 2
Sonali Kala Use next() instead of nextLine() because after taking input using nextLine() cursor moves next line and next line has empty value which is a new line.
20th Dec 2021, 9:32 AM
A͢J
A͢J - avatar
+ 2
A͢J - S͟o͟l͟o͟H͟e͟l͟p͟e͟r͟ but if we use next() then it will print only one word.. I want to print (hello , welcome to my world) Using next () it will print only hello
20th Dec 2021, 9:51 AM
Sonali Kala
Sonali Kala - avatar