Results 1 to 3 of 3
Thread: 2 simple java questions
- 01-31-2008, 05:41 PM #1
Member
- Join Date
- Jan 2008
- Posts
- 22
- Rep Power
- 0
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
- 01-31-2008, 10:51 PM #2
The only error is that in:
\Y is not an escape character (like \n "new line" is), and I think you wished to write "\n\t" intead of "n\t\".System.out.println("n\t\YOUR BODY MASS INDEX IS " + Math.round(index) + ".\n");
- 02-02-2008, 09:35 AM #3
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
-
www.javaadvice.com - The one stop resource for all your Java questions and answers
By JAdmin in forum Reviews / AdvertisingReplies: 0Last Post: 01-24-2008, 07:53 PM -
Simple java
By abhiN in forum New To JavaReplies: 0Last Post: 01-16-2008, 02:44 PM -
Simple java
By abhiN in forum New To JavaReplies: 1Last Post: 01-16-2008, 10:13 AM -
few java questions
By hiaslpix in forum New To JavaReplies: 4Last Post: 01-01-2008, 05:47 AM -
A few questions about Java and design
By ldb88 in forum New To JavaReplies: 4Last Post: 12-07-2007, 12:51 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks