0
why it is not taking String input ?
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);
6 Respostas
+ 16
tldr: Change the input order, so that next line isn't the last called method.
Further infornation:
http://stackoverflow.com/questions/13102045/scanner-is-skipping-nextline-after-using-next-nextint-or-other-nextfoo
+ 15
The ENTER user presses after int/double (non-string) input, is considered as the next String input. You can change the order as Tashi suggested, or put one extra scan.nextLine() to consume the Enter.
https://code.sololearn.com/cNgcAvH5PnM9/?ref=app
+ 13
It's said in the source I linked.
+ 10
What isn't taking string input? Code playground? Could you post the full example code?
0
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);
}
}
0
i know the solution but why it is not printing...