-
Notifications
You must be signed in to change notification settings - Fork 5.7k
Expand file tree
/
Copy pathMain.java
More file actions
30 lines (21 loc) · 933 Bytes
/
Main.java
File metadata and controls
30 lines (21 loc) · 933 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
System.out.println("Let's calculate the area of a triangle");
Scanner input = new Scanner(System.in);
System.out.println("Please input the base of the triangle (in inches).");
double base = input.nextDouble()
while (base <= 0) {
System.out.println("That's invalid. Please input the base of the triangle (in inches).");
base = input.nextDouble();
}
System.out.println("Please input the height of the triangle (in inches).");
double height = input.nextDouble();
while (height <= 0) {
System.out.println("That's invalid. Please input the base of the triangle (in inches).");
base = input.nextDouble();
}
double area = (base * height) / 2;
System.out.println("The area is " + height);
}
}