Im writing code to read an integer value, maybe a float, a double, and then finally read a string. What happens is that I enter the int, press enter after which the execution should stop until I enter a string. However, as soon as I press the enter to go to a newline, I get the outout which is only the number, because execution doesnt pause for me to enter the string. Whats going on
Tried inputting number and then string, that works. Tried inputting number followed by number,that works, tried inputting several strings, that works, but i couldnt get the program to read a number and then a string.
package test;
import java.util.Scanner;
public class Trying {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int i = scan.nextInt();
double d=scan.nextDouble();
String s=scan.nextLine();
scan.close();
System.out.println("String: \'" + s+"\'");
System.out.println("Double: " + d);
System.out.println("Int: " + i);
}
}
I dont get an output for the string