查詢三角形面積的 Java 程式
三角形面積是其底邊和高的一半乘積。因此,要計算三角形的面積。
- 從使用者那裡獲取三角形的高。
- 從使用者那裡獲取三角形的底邊。
- 計算它們乘積,並將結果除以 2。
- 列印最終結果。
示例
import java.util.Scanner;
public class AreaOfTriangle {
public static void main(String args[]){
int height, base, area;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the height of the triangle ::");
height = sc.nextInt();
System.out.println("Enter the base of the triangle ::");
base = sc.nextInt();
area = (height* base);
System.out.println("Area of the triangle is ::"+area);
}
}輸出
Enter the height of the triangle :: 14 Enter the base of the triangle :: 5 Area of the triangle is ::70
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP