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