-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUserInput.java
More file actions
37 lines (33 loc) · 976 Bytes
/
Copy pathUserInput.java
File metadata and controls
37 lines (33 loc) · 976 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package ChapterFive;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
/**
* class to get the user's guess.
* Created by DanielleErickson on 9/11/14.
*/
public class UserInput {
/**
* method to get input from the user and returns it.
* @param prompt
* @return
*/
public String getUserlnput(String prompt){
String inputLine = null;
System.out.print(prompt + " ");
try{
BufferedReader is = new BufferedReader(
new InputStreamReader(System.in));
inputLine = is.readLine();
if (inputLine. length () == 0 ) return null;
} catch (IOException e){
System.out.println("IOException: " + e);
}
System.out.println(inputLine);
return inputLine;
}
public static void main(String [] args){
UserInput ug = new UserInput();
ug.getUserlnput("Type Something");
}
}