Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-31-2008, 06:41 PM
Member
 
Join Date: Jan 2008
Posts: 18
jimJohnson is on a distinguished road
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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 01-31-2008, 11:51 PM
scuffia's Avatar
Member
 
Join Date: Jan 2008
Location: Cagliari (Italy)
Posts: 7
scuffia is on a distinguished road
The only error is that in:
Quote:
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\".
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-02-2008, 10:35 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 839
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
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:
Code:
// put code here...
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
to our beloved Java Forums!
(closes on September 4, 2008)
Want to voice your opinion on your IDE/Editor of choice?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
!
Got a little Capt'n in you? (drink responsibly)
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
www.javaadvice.com - The one stop resource for all your Java questions and answers JAdmin Reviews / Advertising 0 01-24-2008 08:53 PM
Simple java abhiN New To Java 0 01-16-2008 03:44 PM
Simple java abhiN New To Java 1 01-16-2008 11:13 AM
few java questions hiaslpix New To Java 4 01-01-2008 06:47 AM
A few questions about Java and design ldb88 New To Java 4 12-07-2007 01:51 AM


All times are GMT +3. The time now is 09:58 PM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org