Answers for "how to give enter after nextint in java"

4

java scanner string nextline after nextint

//The problem is with the input.nextInt() method - it only reads the int value. So when you continue reading with input.nextLine() you receive the "\n" Enter key. So to skip this you have to add the input.nextLine(). Hope this should be clear now.

//Try it like that:

System.out.print("Insert a number: ");
int number = input.nextInt();
input.nextLine(); // This line you have to add (It consumes the \n character)
System.out.print("Text1: ");
String text1 = input.nextLine();
System.out.print("Text2: ");
String text2 = input.nextLine();
Posted by: Guest on August-24-2020
3

How to do press enter to continue in java

System.out.println("Press enter to continue");
try{System.in.read();}
        catch(Exception e){}
Posted by: Guest on April-26-2020

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language