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); } }
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.
+ 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