Results 1 to 2 of 2
  1. #1
    ThretZ is offline Member
    Join Date
    Nov 2012
    Posts
    2
    Rep Power
    0

    Default Need some help on my if statment.

    Hello, I need some help with my if statement.
    I want to create a simple text base game.
    The game begin with the character reaching the top floor of a castle and encounters the final boss. The character can has two choices, fight or kneel before the boss.

    Right now if i type "fight" it display the following message, "You have decided to fight"
    and if i type "knee" it will display the following "You have decided to join the Bloody Mistress"

    How could i add an if statement into an if statement.
    So if I type "fight" it display the following message, "You have decided to fight" followed by typing "axe" to display "You used your axe, your attack was avoided");

    Can someone please help me!
    Here are my codes:

    Java Code:
    import java.util.Scanner;
    public class TxtG
    {
    	public static String A = "fight";
    	public static String B = "axe";
    	public static String C = "kneel";
    	
    	public static void main(String[] args)
    	{
    		Scanner x = new Scanner(System.in);
    		
    		System.out.println("You gave reached the 100th Floor of the Castle of Blood");
    		System.out.println("The Bloody Mistress awaits you at the center of the room");
    		System.out.println("Will you fight her?");
    		System.out.println("Or will you kneel before her?");
    		
    		System.out.println("Choice: ");
    		String i = x.nextLine();
    		
    	if(i.equals(A))
    	{
    		System.out.println("You have decided to fight");
    		
    		if(A.equals(B))
    		{
    			System.out.println("You used your axe, your attack was avoided");
    		}
    	}
    	else if(i.equals(C))
    	{
    		System.out.println("You have decided to join the Bloody Mistress");
    		System.out.println("You will help her kill the Priestess of Hope");
    	}
    	}	
    }
    Last edited by quad64bit; 11-06-2012 at 04:17 PM. Reason: Formatting

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default Re: Need some help on my if statment.

    Hello and welcome! Please use [code][/code] tags when posting code so we can easily read it!

    Forum Rules
    Guide For New Members
    BB Code List - Java Programming Forum

    I have added code tags for you.

    This article might help you: The if-then and if-then-else Statements (The Java™ Tutorials > Learning the Java Language > Language Basics)

Similar Threads

  1. if statment not working good
    By nour in forum New To Java
    Replies: 3
    Last Post: 03-25-2012, 09:29 PM
  2. Missing Return Statment, HELP PLEASE.
    By dburgess in forum New To Java
    Replies: 2
    Last Post: 06-05-2011, 07:40 PM
  3. If statment not working:(
    By Harris68 in forum Networking
    Replies: 6
    Last Post: 02-24-2010, 10:41 PM
  4. statment replay!!!
    By moamen in forum New To Java
    Replies: 4
    Last Post: 09-25-2009, 12:49 PM
  5. Issue using FOR statment with NetBeans
    By Deathmonger in forum Advanced Java
    Replies: 3
    Last Post: 07-30-2008, 12:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •