Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

boolean game

802991Oct 4 2010 — edited Oct 5 2010
Hello there. Trying to make a boolean game, and thought about haveing a randomizer, so people cannot just memorize the order.

import java.util.*;
public class Boolean_and_if_testing
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.println("Hello there! We will be playing a game. 25 percent chance to win. Choose one: True/False.");
boolean ans = in.nextBoolean();
if (ans == false)
System.out.println("You have lost!!! D:");
if (ans == true)
System.out.println("You have won! :D\nNow choose another choice: True/False.");
if (ans == false)
System.exit(1);
if (ans == true)
ans = in.nextBoolean();
if (ans == true)
System.out.println("You have lost!!! D:");
if (ans == false)
System.out.println("You have won! :D");
}
}

Any help?

Sorry for the layout of the code, I am new to the forums and do not know how to do the code format.
This post has been answered by 798692 on Oct 5 2010
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 2 2010
Added on Oct 4 2010
5 comments
365 views