查詢矩形面積的 Java 程式


矩形面積是其長度和寬度的乘積。因此,要計算矩形的面積

  • 從使用者處獲取矩形的長度。
  • 從使用者處獲取矩形的寬度。
  • 計算它們的乘積。
  • 列印乘積。

示例

以下是使用Scanner 類在 Java 中查詢矩形面積的示例。

import java.util.Scanner;
public class AreaOfRectangle {
   public static void main(String args[]){
      int length, breadth, area;
      Scanner sc = new Scanner(System.in);
      System.out.println("Enter the length of the rectangle ::");
      length = sc.nextInt();
      System.out.println("Enter the breadth of the rectangle ::");
      breadth = sc.nextInt();
      area = length* breadth;
      System.out.println("Area of the rectangle is ::"+area);
   }
}

輸出

Enter the length of the rectangle ::
56
Enter the breadth of the rectangle ::
48
Area of the rectangle is ::2688

更新於:2024-6-18

已檢視 12K+ 次

開啟您的職業

透過完成課程獲得認證

開始
廣告
© . All rights reserved.