Last active
August 29, 2015 14:02
-
-
Save GeorgiPachov/bcc51f1fc3b3a1de1bce to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//package com.hackbulgaria.corejava.oopfun; | |
//or similiar | |
import java.io.BufferedReader; | |
import java.io.IOException; | |
import java.io.InputStreamReader; | |
public class Console { | |
private BufferedReader reader; | |
public String readLine(String prompt) { | |
System.out.print(prompt); | |
try { | |
final String result = bufferedReader().readLine(); | |
System.out.println(); //add a new line | |
return result; | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
return null; | |
} | |
public void writeLine(String output){ | |
System.out.println(output); | |
} | |
private BufferedReader bufferedReader() { | |
return reader == null? (reader = new BufferedReader(new InputStreamReader(System.in))) : reader; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment