Java Scanner Usage confirmAction(String warning)

Here you can find the source of confirmAction(String warning)

Description

confirm Action

License

Apache License

Declaration

public static boolean confirmAction(String warning) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.Scanner;

public class Main {
    public static boolean confirmAction(String warning) {
        System.out.println(warning);
        System.out.print("Are you sure you want to do this? (yes/no): ");
        Scanner in = new Scanner(System.in);
        while (true) {
            try {
                String input = in.nextLine();
                if ("yes".equals(input)) {
                    return true;
                } else if ("no".equals(input)) {
                    return false;
                } else {
                    System.out.println("Please type yes or no");
                }/*  w  w  w  .j  a  v a 2s . c om*/
            } finally {
                in.close();
            }
        }
    }
}

Related

  1. close()
  2. common(Scanner in)
  3. computeSumTable(Scanner in, short n)
  4. confirm(String message)
  5. confirm(String message)
  6. countFileLines(Scanner fin)
  7. createKeyboardScanner()
  8. createScannerForString(String s)
  9. enterToContinue()