- import java.util.Scanner;
- public class Ch01
- {
-
- static float getArea(float a,float b)
- {
- return (a*b)/2;
- }
-
- public static void main(String[] args)
- {
- Scanner s=new Scanner(System.in);
- float x,y;
- System.out.print("請輸入三角形的底(公分): ");
- x=s.nextFloat();
- System.out.print("請輸入三角形的高(公分): ");
- y=s.nextFloat();
- System.out.println("底"+x+"公分, "+"高"+y+"公分的三角形, 面積為: "+
- getArea(x,y)+"平方公分");
- }
- }
複製代碼 |