Results 1 to 4 of 4
  1. #1
    xxgetownedxx is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Question Help! I don't know whats wrong.

    So I'm new to java and learning new stuff here and there. I decided to test out my abilities (I just started yesterday) and create an extremely simple RPG character creation text game. I wrote all the code and everything and when I run it it works fine for the first 3 questions. Then when I get to the fourth question. It asks 2 questions at the same time and only lets me answer one. After that all the rest of the questions are screwed up and not answerable.
    Here is the code:

    import java.util.Scanner;

    public class TextGame {
    public static void main(String args[]){
    Scanner player = new Scanner(System.in);
    String name, gender, race, build, path;
    double height;
    int age;

    System.out.println("What is your name?");
    name = player.nextLine();

    System.out.println("What is your gender?");
    gender = player.nextLine();

    System.out.println("How old are you?");
    age = player.nextInt();

    System.out.println("What race are you?");
    race = player.nextLine();

    System.out.println("What type of body build do you have?(Fat, skinny, muscular, etc...)");
    build = player.nextLine();

    System.out.println("How tall are you?(Feet)");
    height = player.nextDouble();

    System.out.println("What class are you?(Warrior, mage, archer, etc...)");
    path = player.nextLine();

    System.out.println("So you are a " + age + "year-old" + build + gender + race + path + "that is " + height + "ft tall, named " + name + "?" );
    player.close();
    }


    }
    //End of RPG test



    Now when I run it this what I get in console, I put x and 1 for place holders:

    What is your name?
    x
    What is your gender?
    x
    How old are you?
    1
    What race are you?
    What type of body build do you have?(Fat, skinny, muscular, etc...)
    x
    How tall are you?(Feet)
    1
    What class are you?(Warrior, mage, archer, etc...)
    x
    So you are a 1 year-old x x x that is 1.0 ft tall, named x.


    What race are you?
    What type of body build do you have?(Fat, skinny, muscular, etc...)
    x
    Problem


    Can someone explain to me why its doing this and tell me how to fix this? Please! Thanks for reading! :)

  2. #2
    jim829 is online now Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,421
    Rep Power
    5

    Default Re: Help! I don't know whats wrong.

    Put in another nextLine() after the nextInt(). The line terminator is still in the buffer so you need to clear it out. Also, please read the FAQ and guide for new members. And place your code between code tags. [code][/code].

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    xxgetownedxx is offline Member
    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Default Re: Help! I don't know whats wrong.

    Thank you!

  4. #4
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,184
    Rep Power
    19

    Default Re: Help! I don't know whats wrong.

    Please go through the Forum Rules, particularly the third paragraph.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

Similar Threads

  1. Whats wrong??
    By javaa in forum New To Java
    Replies: 3
    Last Post: 08-29-2012, 01:47 PM
  2. I cant do this.Whats wrong?
    By gaston7eze in forum Java 2D
    Replies: 5
    Last Post: 05-30-2012, 12:34 AM
  3. Whats wrong with this?
    By Alkor in forum AWT / Swing
    Replies: 7
    Last Post: 04-03-2012, 05:49 AM
  4. whats wrong
    By atenv in forum New To Java
    Replies: 6
    Last Post: 06-15-2010, 01:55 PM
  5. whats is wrong with this app??
    By mrajan in forum New To Java
    Replies: 4
    Last Post: 06-09-2010, 10:56 PM

Posting Permissions

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