Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Need some help on my if statment.

  1. #1
    Junior Member
    Join Date
    Mar 2012
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    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:

    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");
    }
    }
    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 555 Times in 476 Posts

    Default Re: Need some help on my if statment.

    When posting code, please use highlight tags to preserve formatting.

    It sounds like you just want to read in another line and check it. Is that right?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Mar 2012
    Posts
    12
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Need some help on my if statment.

    Thats right. How would i do it?

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    4,972
    My Mood
    Hungover
    Thanks
    133
    Thanked 555 Times in 476 Posts

    Default Re: Need some help on my if statment.

    Well, you've already read in one line. How did you do that?
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. If/Else Statment Help
    By aandcmedia in forum What's Wrong With My Code?
    Replies: 1
    Last Post: January 17th, 2012, 03:10 PM
  2. Else-if statment failure
    By tyb97 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: September 17th, 2011, 08:52 PM
  3. [SOLVED] My string is not activating my if statment.
    By ZeroLRS in forum What's Wrong With My Code?
    Replies: 8
    Last Post: July 8th, 2011, 06:11 PM
  4. Switch Statment
    By 3XiLED in forum Java Theory & Questions
    Replies: 2
    Last Post: March 31st, 2010, 05:11 PM
  5. Having trouble with a While statment
    By java0 in forum Loops & Control Statements
    Replies: 1
    Last Post: January 27th, 2010, 11:37 AM