正方形面積計算

練習的參考答案,僅供參考:

package com.example;

import java.util.Scanner;

/**
 * 正方形面積計算
 */
public class Area {
    public static void main(String[] args) {
        String desc = "正方形";
        System.out.println("請輸入" + desc + "的邊長:");
        Scanner scanner = new Scanner(System.in);
        double border = scanner.nextDouble();
        double area = Math.pow(border, 2);
        System.out.println("所計算的" + desc + "的面積是:" + area);
    }
}

你可能感兴趣的:(正方形面積計算)