Skip to content

Instantly share code, notes, and snippets.

@sivabudh
Created March 5, 2014 12:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sivabudh/9366210 to your computer and use it in GitHub Desktop.
Save sivabudh/9366210 to your computer and use it in GitHub Desktop.
How to calculate triangle area from command line inputs
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