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.


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

Results 1 to 2 of 2

Thread: Cant get my code to stop jumping

  1. #1
    Junior Member
    Join Date
    Feb 2011
    Thanked 0 Times in 0 Posts

    Default URGENT!!!!! Cant get my code to stop jumping

    Im trying to prompt the user to pick 1 or 2 but if i pick 1 it still ask me the choice 2 questions?

    import java.util.Scanner;
    public class Assignment9Lozano
    {       // Open Assignment9Lozano
            public static void main ( String[] args)
            {      //Open Main
                   /***** Declare Variables *****/
                   int Choice, unit;
                   double mass, height, bodyMassIndex;        
                    String name;
                    Scanner input= new Scanner( System.in );
                   //     Prompt User for Entry //
                     System.out.print( " Whats is your name? ");
                     System.out.println( "\n");
                     name = input.nextLine();
                    System.out.print("\n\n What unit system would you like to use?");
                    System.out.print("\n 1= SI or 2= English\n");  
                    System.out.println("\n\n Choice = " + Choice);
                   if (Choice==1)  
                     System.out.print( " What is your mass (kg)? ");
                     mass = input.nextDouble();
                     System.out.print( " What is your height (meters)? ");
                     height = input.nextDouble();
                    else if (Choice ==2);
                     System.out.print(" What is your mass (pounds)? ");
                     mass = input.nextDouble();
                     System.out.print(" What is your height ( feet and inches)? ");
                     height= input.nextDouble();
                    // Calculating Body Mass Index
                    bodyMassIndex = mass/ Math.pow(height,2);
                   //     Print Output to Computer Screen
                     System.out.println(name + " your mass is " + mass + " kg, your height is" + height + " meters, and your BMI is" + bodyMassIndex + ".");
              }  //end main
     }        // Assignment9
    Last edited by Mob31; March 1st, 2011 at 09:15 PM.

  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    United Kingdom
    My Mood
    Thanked 293 Times in 226 Posts
    Blog Entries

    Default Re: Cant get my code to stop jumping

    Hello Mob31,

    Please don't write URGENT!!!! in your thread titles. Everyones issue is urgent as far as they are concerned.
    People will help answer your question as soon as possible regardless of you writing this.

    The problem here is with your if statement.

    Take a look at this line:

    else if (Choice ==2);

    You need to remove the semicolon ;

    This will work fine now!

    Also, please make sure you initialize your variables.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Stop Access Table Locking
    By aussiemcgr in forum JDBC & Databases
    Replies: 4
    Last Post: February 4th, 2011, 07:23 PM
  2. can' stop working a part of code.plzz help
    By kyros in forum What's Wrong With My Code?
    Replies: 2
    Last Post: October 30th, 2010, 03:10 PM
  3. paying off dept ( can't make it stop at 0 )
    By bossmeister in forum What's Wrong With My Code?
    Replies: 3
    Last Post: September 16th, 2010, 07:33 AM
  4. Code Stop working after converting to jar?
    By Ron6566 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: August 16th, 2010, 12:17 PM
  5. radio buttons stop working
    By tabutcher in forum AWT / Java Swing
    Replies: 2
    Last Post: March 5th, 2010, 09:28 AM