Results 1 to 3 of 3
  1. #1
    jimJohnson is offline Member
    Join Date
    Jan 2008
    Posts
    22
    Rep Power
    0

    Default 2 simple java questions

    This is my first time making a programming post so could somesome instruct me how to make code takes to make it easier on you guys. Also I am going to show you my code and the error I am getting. The error is:

    C:\Documents and Settings\bkruep\My Documents\Bodymass.java:40: illegal escape character
    System.out.println("n\t\YOUR BODY MASS INDEX IS " + Math.round(index) + ".\n");

    and my code is:

    //Filename: Bodymass.java
    //This program calculates the body mass index based on a person's height and weight is a command prompt console application


    //package to import for input and output
    import java.io.*;

    public class Bodymass
    {
    //main () method is where execution begins
    public static void main (String[] args) throws IOException
    {
    //declare variables
    String height, weight;
    int inches, pounds;
    double kilograms, meters, index;

    //construct a BufferedReader object
    BufferedReader dataIn = new BufferedReader(new InputStreamReader(System.in));

    //prompt user and get input
    System.out.println("\tTHE SUN FITNESS CENTER BODY MASS INDEX CALCULATOR");
    System.out.println();
    System.out.print("\t\tEnter your height to the nearest inch: ");
    height = dataIn.readLine(); //brings input in as a String
    inches = Integer.parseInt(height);
    System.out.print("\t\tEnter your weight to the nearest pound: ");
    weight = dataIn.readLine();
    pounds = Integer.parseInt(weight);

    //perform calculations
    meters = inches / 39.36;
    kilograms = pounds /2.2;
    index = kilograms / Math.pow(meters, 2);

    //display output
    System.out.println();
    System.out.println("n\t\YOUR BODY MASS INDEX IS " + Math.round(index) + ".\n");
    System.out.println();



    }//end main
    }//end class

  2. #2
    scuffia's Avatar
    scuffia is offline Member
    Join Date
    Jan 2008
    Location
    Cagliari (Italy)
    Posts
    7
    Rep Power
    0

    Default

    The only error is that in:
    System.out.println("n\t\YOUR BODY MASS INDEX IS " + Math.round(index) + ".\n");
    \Y is not an escape character (like \n "new line" is), and I think you wished to write "\n\t" intead of "n\t\".

  3. #3
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    10

    Default

    Quote Originally Posted by jimJohnson View Post
    This is my first time making a programming post so could somesome instruct me how to make code takes to make it easier on you guys.
    ....
    I appreciate your concern, and I sincerely mean that. The code tags can found in the Advanced version of the posting window. Otherwise, simply follow this syntax, use
    [code]
    // put code here...
    [ /code](without the space between the '[' and '/') to get this wrapper:
    Java Code:
     // put code here...
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

Similar Threads

  1. Replies: 0
    Last Post: 01-24-2008, 08:53 PM
  2. Simple java
    By abhiN in forum New To Java
    Replies: 0
    Last Post: 01-16-2008, 03:44 PM
  3. Simple java
    By abhiN in forum New To Java
    Replies: 1
    Last Post: 01-16-2008, 11:13 AM
  4. A few questions about Java and design
    By ldb88 in forum New To Java
    Replies: 4
    Last Post: 12-07-2007, 01:51 AM

Posting Permissions

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