Triangle Area Program
I need to add a floating decimal and a if statement to this program. Can anyone help me out? I am not sure if the program will compile and run as is.
// import statement
import java.util.Scanner;
/*
* Author: Daniel Wood
* Date: 2006.01.26
* Revision History: N/A
*/
public class TriangleArea
{
static int number_1 = 0; //stores the first value entered (Base)
static int number_2 = 0; //stores the second value entered (Height)
static int sum = 0; //strores the value of .5 * number_1(Base) * number_2(Height)
public static void main (String args[] ) {
Scanner myScannerReference = new Scanner(System.in );
//Instansiates scanner class
// Read in the data
System.out.print("Please enter the base: ");
number_1 = myScannerReference.nextInt();
System.out.print("Please enter the height: ");
number_2 = myScannerReference.nextInt();
//Compute the sum
sum = number_1 * number_2 * (1/2);
// Print the result
System.out.println("The Area of " + number_1 + " and " + number_2 + " is " + sum );
// Outline the ASCII Triangle and display its dimensions
System.out.print(" *");
System.out.print(" * *");
System.out.print(" * *");
System.out.print("Height" +"**");
System.out.print("number_1"+ "**");
System.out.print(" **");
System.out.print(" *******");
System.out.print("Base");
System.out.print(number_2);
} // end method main()
} // end class TriangleArea
[1576 byte] By [
Dwooda] at [2007-10-2 10:59:52]

> I am not sure if the program will compile and run as is.
You can compile it by going to the directory that contains
TriangleArea.java and executing the command
javac -classpath . TriangleArea.java
It's a good idea to use the "code" button (right above where you
composed your post). Select the code and click the code button -
this will ensure that the code is formatted properly.
If you get an error from the compiler that you can't understand, post it
here (cut and paste so there aren't any typos). If the error message
includes a line number, don't forget to say which line of your code
it is referring to.
> i typed in set path and .java is not showing up as an
> extension
Okay.
Please do the following.
Close the DOS/cmd window you are working with.
Open a new one.
Type path and hit enter.
What does that say?
If Java does not show up then type the following
path=c:\Program Files\Java\jdk1.5.0_04\bin
and hit enter. This will set you path for THIS WINDOW ONLY.
Now type javac and hit enter.
Does that work? If not then you have the wrong path to your install. If it does work then we just need to set your path permanently.
Go into your system properties (right click my computer or Start -> Settings - > Control Panel -> System)
Choose the Advanced Tab
Choose the Environment Variables.
Edit the user (or system if you have multiple accounts) variable PATH/path
Add that directory to the end of the path. The path seperator is a semi colon.
So if you have a path like this
C:\perl
Then the new path will be
C:\perl;c:\Program Files\Java\jdk1.5.0_04\bin
Then click Ok. Ok again. Apply. Then ok.
Then open a new window. (When you make changes to the path it does NOT update existing cmd shells)
PS cmd is the DOS window... and the reason I am not calling it DOS before is that it actually isn't DOS just looks and smells the same.
at 2007-7-20 20:58:51 >
