Skip to content

Commit 8a35d15

Browse files
committed
feat: Add Expression class to calculate area of a triangle using user input
Add a program that: - Takes base and height as floating-point inputs from the user - Calculates the area using the formula (base × height) / 2 - Outputs the computed area - Demonstrates the use of arithmetic expressions and `Scanner` class for input.
1 parent 4ab745b commit 8a35d15

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

Section5OperatorExpression/src/Expression.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,18 @@
22
import java.util.Scanner;
33

44
class Expression {
5-
public static void main(String args[])
6-
{
5+
public static void main(String args[]) {
76
float base;
87
float height;
98
float area;
109

11-
System.out.println("Enter Base and Height ");
12-
Scanner sc = new Scanner(System.in); //Read the value
10+
Scanner sc = new Scanner(System.in);
11+
System.out.println("Enter Base and Height: ");
1312

1413
base = sc.nextFloat();
1514
height = sc.nextFloat();
1615

1716
area = base * height / 2;
1817
System.out.println("Area of Triangle is " + area);
1918
}
20-
}
19+
}

0 commit comments

Comments
 (0)