Java Scanner Usage waitForEnter()

Here you can find the source of waitForEnter()

Description

Calling this method waits until the user presses enter (scans standard input for next line), writing a default message to standard output: "[Press enter to continue]".

License

Apache License

Declaration

public static void waitForEnter() 

Method Source Code


//package com.java2s;
//  Licensed under the Apache License, Version 2.0 (the "License");

import java.util.Scanner;

public class Main {
    /**// w  w  w .  j a v  a  2s .c om
     * Calling this method waits until the user presses enter (scans standard input for next line), writing
     * a default message to standard output: "[Press enter to continue]".
     */
    public static void waitForEnter() {
        waitForEnter("[Press enter to continue]");
    }

    /**
     * Calling this method waits until the user presses enter (scans standard input for next line), writing
     * a given message to standard output.
     * 
     * @param message message to write to standard output before waiting for enter
     */
    public static void waitForEnter(String message) {
        Scanner in = new Scanner(System.in);
        System.out.print(message);
        in.nextLine();
    }
}

Related

  1. toNumeric(String ip)
  2. toWords(String content)
  3. transformTXTandANNtoRQS(String TXT, String ANN)
  4. trim(String s)
  5. validateInt(Scanner keyboard, String message, String error)
  6. waitForStopSignal()
  7. wrap(String msg, int wrapWidth, int wrapTolerance)