1. 程式人生 > >java語言程式設計(基礎篇)第十版程式設計練習題[1.9]

java語言程式設計(基礎篇)第十版程式設計練習題[1.9]

(矩形的面積和周長)編寫程式,使用以下公式計算並顯示寬度為4.5、高度為7.9的矩形的面積和周長。

面積 = 寬 × 高
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package dome1_9;

/**
 *
 * @author Administrator
 */
public class Dome1_9 { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO code application logic here double S = 0.0; double perimeter = (4.5 + 7.9) * 2; S = 4.5 * 7.9; System.out.println("面積:"
+ S); System.out.println("周長:" + perimeter); } }