By BoLOBOSE payday loan

Create a press enter to continue with java

Sometime a pause in your program is needed and the process of implementing this is easier then you would think. It involves one simple method that we will call into our main method when we need to pause.

1
2
3
4
5
6
7
8
9
10
11
12
13
import java.util.Scanner;
public class appletTest1{
 
public static void main(String[] args) {
pauseProg();
 
}
public static void pauseProg(){
System.out.println("Press enter to continue...");
Scanner keyboard = new Scanner(System.in);
keyboard.nextLine();
}
}

The only important piece of code here that you will need to go over is the ‘keyboard.nextLine();’ This will take the object we created earlier in the program and set the next line breaker which is enter. When the program runs up to this line it waits for the user to import a string. By pressing enter you then process that string which does nothing because it does not get stored into a variable. The line breaks and the program continues.

Related posts:

  1. Creating user input with menus in java
  2. Java: Pass as many strings as you want through a method
  3. Writing and reading objects and arrays to a binary file with java
  4. Writing information to a binary file in java
  5. Reading information from a binary file with java
Caleb Jonasson

About: Caleb Jonasson

I am a web application developer currently spending my days coding at work, completing contracts and running around with my Nikon. This is my primary place for updates and everything code, technology and database related.
  • james ruthe

    And it was so simple…
    Thanks.

  • Guest

    thx,, that is a very simple helpful code,, *thumbUp*

  • Abc

    Thank you very much.

  • Jacky

    thanks !

  • http://www.ocularconcepts.us/ Website Design Company

    thanks for sharing

  • Flames

    thanks mate :))))