Skip to content

Instantly share code, notes, and snippets.

@tedheich
Created November 26, 2009 14:09
Show Gist options
  • Save tedheich/243477 to your computer and use it in GitHub Desktop.
Save tedheich/243477 to your computer and use it in GitHub Desktop.
Accept Input from keyboard - a bit more modularized
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.IOException;
class Repl {
InputStreamReader isr = null;
BufferedReader br = null;
Repl() {
isr = new InputStreamReader(System.in);
br = new BufferedReader(isr);
}
String Prompt(String prompt) {
System.out.print("% " + prompt + " : ");
String retval = null;
try {
retval = br.readLine();
}
catch(IOException ioe) {
ioe.printStackTrace();
}
finally {
return retval;
}
}
public static void main(String []args) {
Repl repl = new Repl();
String fname = repl.Prompt("Enter your first name");
String lname = repl.Prompt("Enter your last name");
System.out.println("Hello " + fname + " " + lname);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment