Adding Inputs into Java proggrams

timer Asked: Jun 17th, 2013
account_balance_wallet $5

Question Description

Hi fellow Java Lovers,
I am currently programming a small game from the knowledge I know, and its just a basic game where you guide yourself around a haunted house and try to find the exit.
Only problem is I don't know how to program user inputs into the program.

eg. Here is a piece of my code
protected void goRightThree()
System.out.println("You walk forward, trying not to make too much noise");
System.out.println("You come to a left turn and right turn which way do you go?");
double randomNumber = Math.random();
if (randomNumber >= 0.5)
System.out.println("You decide to go left");

System.out.println("You decide to go right");

For the time being I just made the direction the user goes as a random decision but what I am aiming to do is make the user of this game be able to choose where he/she goes.
I know people probably thinking I am very new to Java but help would be very nice.

Thanks guys

Tutor Answer

School: UC Berkeley

You have many option to get input form user. you can use below classes for getting input from user.
1)InputStreamReader istream = new InputStreamReader( ;

2)BufferedReader bufRead = new BufferedReader(istream) ;
3)Scanner a = new Scanner(;

if u r using first and second, you need to use readLine() method. On other hand, you need to use nextLine().


flag Report DMCA

Thank you! Reasonably priced given the quality not just of the tutors but the moderators too. They were helpful and accommodating given my needs.

Brown University

1271 Tutors

California Institute of Technology

2131 Tutors

Carnegie Mellon University

982 Tutors

Columbia University

1256 Tutors

Dartmouth University

2113 Tutors

Emory University

2279 Tutors

Harvard University

599 Tutors

Massachusetts Institute of Technology

2319 Tutors

New York University

1645 Tutors

Notre Dam University

1911 Tutors

Oklahoma University

2122 Tutors

Pennsylvania State University

932 Tutors

Princeton University

1211 Tutors

Stanford University

983 Tutors

University of California

1282 Tutors

Oxford University

123 Tutors

Yale University

2325 Tutors