Created
March 5, 2014 12:22
-
-
Save sivabudh/9366210 to your computer and use it in GitHub Desktop.
How to calculate triangle area from command line inputs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class TriangleArea { | |
public static void main(String[] args) { | |
Scanner kb = new Scanner(System.in); | |
System.out.println("This program will help you calculate the area of a triangle."); | |
System.out.print("What's the height of the triangle? "); | |
String heightText = kb.next(); | |
System.out.print("What's the base of the triangle? "); | |
String baseText = kb.next(); | |
int height = Integer.parseInt(heightText); | |
int base = Integer.parseInt(baseText); | |
double area = height * base / 2; | |
System.out.println("Your area is: "+area); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment