Search
 
SCRIPT & CODE EXAMPLE
 

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 
    }
}  
Comment

PREVIOUS NEXT
Code Example
Java :: how to write custom message for repeat password in joi 
Java :: table of any number in java 
Java :: java convert array to another type 
Java :: lombok get error in extended classes¨ 
Java :: spring h2 database dependency 
Java :: how to find length of set in java 
Java :: java create set with values 
Java :: Youtube video thumbnail not load in android 11 or above 
Java :: volley library dependency 
Java :: bukkit java connect player to another server in bungeecord 
Java :: java swing stripes 
Java :: data to string format java 
Java :: change material fab color android 
Java :: public static int to String java 
Java :: alertdialog show in android 
Java :: best ascii art characters 
Java :: java public static void main 
Java :: java connect mariadb 
Java :: java retirer derniere caractere sting 
Java :: Min value map 
Java :: list extension quarkus 
Java :: java sort 2d array 
Java :: java create list of strings 
Java :: java for loop 
Java :: How to convert timestamp to time in java 
Java :: java join list of strings 
Java :: kotlin enable and disable parents view children 
Java :: java print text 
Java :: check array is sorted java 
Java :: unparseable date error in java 
ADD CONTENT
Topic
Content
Source link
Name
4+8 =