|
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
|