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 7 of 7

Thread: Looking for some help! (BEGINNER)

  1. #1
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Looking for some help! (BEGINNER)

    Hello, my name is Nick. I am fairly new to java and am trying to write some multiple choice programs but it seems to only run the whole program no matter what you choose. Here is my code, please help!

    {
    int ans;
    Scanner input = new Scanner(System.in);
    System.out.println("What would you like to do?");
    System.out.println("1)Add 2)Subtract 3)Multiply");
    ans = input.nextInt();

    int x;
    int y;
    int sum;

    if (ans == 1);
    {
    System.out.println("You have choosen addition!");
    System.out.println("Please enter a number");
    x = input.nextInt();
    System.out.println("Please enter another number");
    y = input.nextInt();
    sum = x + y;
    System.out.println("The sum of the two numbers is " + sum);
    }
    System.out.println();

    if (ans == 2);
    {
    System.out.println("You have choosen subtraction!");
    System.out.println("Please enter a number");
    x = input.nextInt();
    System.out.println("Please enter another number");
    y = input.nextInt();
    sum = x - y;
    System.out.println("The subtraction of the two numbers is " + sum);
    }
    System.out.println();

    if (ans == 3);
    {
    System.out.println("You have choosen multiplication!");
    System.out.println("Please enter a number");
    x = input.nextInt();
    System.out.println("Please enter another number");
    y = input.nextInt();
    sum = x * y;
    System.out.println("The multiplication of the two numbers is " + sum);
    }

    if (x <= 1 || x >= 3);
    {
    System.out.println("Invalid command, Try again!");
    }


    input.close();
    }


  2. #2
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Looking for some help! (BEGINNER)

    if (ans == 1); {
        System.out.println("You have choosen addition!");
    Hmmmm!
    Improving the world one idiot at a time!

  3. The Following User Says Thank You to Junky For This Useful Post:

    Graveyard22 (October 13th, 2013)

  4. #3
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Looking for some help! (BEGINNER)

    Any ideas my friend?

  5. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,164
    Thanks
    65
    Thanked 2,725 Times in 2,675 Posts

    Default Re: Looking for some help! (BEGINNER)

    The ; character ends a statement. Make sure the ; are at the end of the statement.

    Use the javac compiler's -Xlint option to get some good warning/error messages.
    D:\Java\jdk1.7.0.7\bin\javac.exe -cp . -Xlint TestCode14.java
    If you don't understand my answer, don't ignore it, ask a question.

  6. The Following User Says Thank You to Norm For This Useful Post:

    Graveyard22 (October 13th, 2013)

  7. #5
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Looking for some help! (BEGINNER)

    Can you test it and send me the proper code because I have tried everything and it wont work. I am using netbeans IDE 7.3.1

  8. #6
    Super Moderator
    Join Date
    Jun 2013
    Location
    So. Maryland, USA
    Posts
    5,517
    My Mood
    Mellow
    Thanks
    215
    Thanked 698 Times in 680 Posts

    Default Re: Looking for some help! (BEGINNER)

    Did you fix the error pointed out in post #2 by Junky and further hinted at by Norm in post #4? If so, post your updated code. If not, reread those posts.

  9. The Following User Says Thank You to GregBrannon For This Useful Post:

    Graveyard22 (October 13th, 2013)

  10. #7
    Junior Member
    Join Date
    Oct 2013
    Posts
    4
    Thanks
    3
    Thanked 0 Times in 0 Posts

    Default Re: Looking for some help! (BEGINNER)

    Nice i fixed it woot! Thx alot guys!

Similar Threads

  1. i'm a beginner
    By so hat in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 24th, 2013, 12:42 AM
  2. beginner
    By reginakanje in forum Object Oriented Programming
    Replies: 2
    Last Post: January 12th, 2013, 06:09 AM
  3. Beginner help please.
    By xdorkiee in forum What's Wrong With My Code?
    Replies: 59
    Last Post: December 20th, 2012, 09:19 PM
  4. hello... i am a beginner...
    By learningjava1 in forum Member Introductions
    Replies: 1
    Last Post: November 24th, 2012, 12:19 PM
  5. Beginner
    By mkarthik90 in forum Member Introductions
    Replies: 1
    Last Post: February 18th, 2012, 02:26 PM