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);
}
}
Asked
Active
Viewed 32 times
-2
Iłya Bursov
- 21,884
- 4
- 31
- 54
Anshika
- 1
- 1
-
add `scan.nextLine();` after `scan.nextDouble();` – Iłya Bursov Apr 04 '17 at 20:05
-
what is your error / output? – victor Apr 04 '17 at 20:05
1 Answers
2
you can use
int i = scan.nextInt();
scan.nextLine();
double d = scan.nextDouble();
scan.nextLine();
String s = scan.nextLine();
Note that, Scanner.nextInt(), Scanner.nextDouble etc doesn't get the last next line. So you need to call them separately.
stinepike
- 52,673
- 14
- 90
- 109