Console.java Source code

Java tutorial

Introduction

Here is the source code for Console.java

Source

import java.util.Scanner;

class Console {

    static Scanner sc = new Scanner(System.in);

    public static boolean askYorN(String prompt) {
        while (true) {
            String answer;
            System.out.print("\n" + prompt + " (Y or N) ");
            answer = sc.next();
            if (answer.equalsIgnoreCase("Y"))
                return true;
            else if (answer.equalsIgnoreCase("N"))
                return false;
        }
    }
}

public class MainClass {
    public static void main(String[] args) {
        while (Console.askYorN("Keep going?")) {
            System.out.println("!");

        }
    }
}