Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

scan.nextline not waiting for input

//scan.nextline(); will skip the input if it is written after scan.nextInt();
//This happens due to Delimiters.
import java.util.Scanner;
public class Training {
	public static void main(String[] args) {
    	Scanner scan=new Scanner(System.in);
      	System.out.println("
Hello. What is your name?");
      	String name=scan.nextLine(); //This scan.nextline(); will take input.
      	System.out.println("
How old are you?");
        int age=scan.nextInt();
      	//once you enter this the next scan.nextline will not work
      	//In order to fix it enter the below first .
      	scan.nextLine();
      	System.out.println("Where are you from?");
        String home=scan.nextLine();
      	//this will take input since scan.nextline(); is used .
      	System.out.println(name); //will output your name
      	System.out.println(age); //will output your age
      	System.out.println(home); //will output your home 
    }
}  
 
PREVIOUS NEXT
Tagged: #waiting #input
ADD COMMENT
Topic
Name
1+8 =