Results 1 to 5 of 5
- 02-01-2012, 08:36 PM #1
loop "play again" in an 8 ball game, loops but ... (by IareSmart)
Reposted because of a forum bug with the word "print" appearing in a thread topic.
The original post was by IareSmart.
db
loop "play again" in an 8 ball game , loops but wont let me answer my "out.print"
Hey this is my first post so if i make a mistake shout at me.
I made an 8ball program but the problem is when it loops is wont let me answer my "out.print("What would u like to ask ? ");" , it just gives me a yes , no or maybe , then asks "out.println("Want to ask another question ?");"
Iv only been learning code for 3 or 4 days so not very good at it xD
Im guessing i need a break; somewhere or another loop ?
heres the code
Java Code:import java.util.Scanner; import static java.lang.System.out; import java.util.Random; class TestFor8Ball { public static void main(String args[]) { Scanner in = new Scanner(System.in); char reply = 'y'; Random myRandom = new Random(); int random; while (reply == 'y' || reply == 'Y') { out.print("What would u like to ask ? "); in.nextLine(); out.println(); random = myRandom.nextInt(10) + 1; if ( random > 5) { out.println("The answer to your question is No"); } else if (random < 5) { out.println("The answer to your question is Yes"); } else { out.println("mmm Maybe i realy dont know"); } out.println(); out.println("Want to ask another question ?"); out.println(); reply = in.findInLine(".").charAt(0); if (reply == 'n' || reply == 'N') { out.println(); out.println("Good Bye"); } } } }Why do they call it rush hour when nothing moves? - Robin Williams
- 02-01-2012, 09:35 PM #2
Re: loop "play again" in an 8 ball game, loops but ... (by IareSmart)
After you ask the question on line 29 what is the value that the user enters and is put into the reply variable?
Add a println to print out those values so you can see what the code is doing.
- 02-01-2012, 10:56 PM #3
Member
- Join Date
- Feb 2012
- Posts
- 3
- Rep Power
- 0
Re: loop "play again" in an 8 ball game, loops but ... (by IareSmart)
Thanks for reposting , i got it to work but didnt use a loop
Java Code:import java.util.Scanner; import java.util.Random; import static java.lang.System.out; class Ball { public static void Ball8(){ Scanner in = new Scanner(System.in); Random myRandom = new Random(); int random; out.print("What would u like to ask ? "); in.nextLine(); out.println(); random = myRandom.nextInt(10) + 1; if ( random > 5) { out.println("The answer to your question is No"); } else if (random < 5) { out.println("The answer to your question is Yes"); } else { out.println("mmm Maybe i realy dont know"); } out.println(); out.println("Ask another question"); out.println(); Replay(); } public static void Replay(){ Scanner in = new Scanner(System.in); char reply; reply = in.findInLine(".").charAt(0); if (reply == 'Y' || reply == 'y'){ System.out.println(); new Ball().Ball8(); }else{ out.println(); out.println("Good Bye"); } } public static void main(String[] args) { new Ball().Ball8();
- 02-02-2012, 08:28 PM #4
Re: loop "play again" in an 8 ball game, loops but ... (by IareSmart)
Please stop wearing out my scroll wheel with inordinate amounts of vertical whitespace (blank lines to you).
Code Conventions for the Java Programming Language: Contents
dbWhy do they call it rush hour when nothing moves? - Robin Williams
- 02-03-2012, 01:55 PM #5
Member
- Join Date
- Feb 2012
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
loop "play again" in an 8 ball game , loops but wont let me answer my "out.print"
By IareSmart in forum New To JavaReplies: 1Last Post: 02-01-2012, 08:37 PM -
Play soundclip and generate"wind" like sound
By diablo2070 in forum New To JavaReplies: 5Last Post: 03-13-2011, 08:47 PM -
Is there a way to play the video until I click the "start "button?
By aprilcomingsoon in forum XMLReplies: 0Last Post: 06-07-2010, 06:23 PM -
An "if" statement inside a "for" loop?
By soccermiles in forum New To JavaReplies: 18Last Post: 04-20-2010, 03:44 AM -
the dollar sign "$", prints like any other normal char in java like "a" or "*" ?
By lse123 in forum New To JavaReplies: 1Last Post: 10-20-2008, 07:35 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks