Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    error message 26 and do not know why

    Could someone advise me why I am receiving the above error message...


    import javax.swing.JOptionPane;
    import java.util.Scanner; // Needed for the Scanner Class

    /** This program demonstrates using dialogs
    * with JOptionPane.
    *
    */

    /** This program calculates three instances
    * to obtain BodyMassIndex by passing
    * arugments to if statements.
    */

    public class BodyMassIndex

    {
    public static void main(String[] args)
    {
    String inputString; // For reading input
    double weight; // The user's weight
    double height; // The user's height
    bodyMassIndex // The user's body mass index


    // Create a Scanner object for keyboard input.
    Scanner keyboard = new Scanner(System.in);

    // Get the user's weight.
    inputString =
    JOptionPane.showInputDialog("What is " +
    "your weight in pounds? ");
    weight = keyboard.nextDouble();


    // Get the user's height.
    inputString =
    JOptionPane.showInputDialog("What is " +
    "your height in inches? ");
    height = keyboard.nextDouble();


    // Calculate the body mass index.
    bodyMassIndex = weight * 703 / Math.pow(height, 2.0);



    // Display the results.
    {
    if (bodyMassIndex > 25)
    System.out.println("You are overweight");

    if (bodyMassIndex >= 18.5 && bodyMassIndex <= 25)
    System.out.println("You are at optimal weight");

    if (bodyMassIndex < 18.5)
    System.out.println("You are underweight");

    }

    System.exit(0);

    }
    }

  • #2
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,987
    Thanks
    4
    Thanked 2,660 Times in 2,629 Posts
    bodyMassIndex isn't declared properly. It needs a datatype and a semi-colon.

    Also, you are mixing swing and cli here. Once you've been prompted for input in the gui, you'll then need to proceed and enter on the command line. Choose to either use an entire gui application and stick with the swing components, or drop the swing and run it on the command line. Don't mix the two.
    Also, in the future please wrap your code in [php][/php] or [code][/code] tags to preserve the formatting.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 


  •  

    Posting Permissions

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