查找矩形面积的 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP