JAVA求圆和矩形面积周长
时间: 2023-05-21 11:07:01 浏览: 88
很抱歉,我不太清楚您的问题。我可以向您提供有关计算圆和矩形面积周长的JAVA代码:
计算圆的面积:
double radius = 5.0;
double area = Math.PI * radius * radius;
计算圆的周长:
double radius = 5.0;
double circumference = 2 * Math.PI * radius;
计算矩形的面积:
int width = 10;
int height = 20;
int area = width * height;
计算矩形的周长:
int width = 10;
int height = 20;
int circumference = 2 * (width + height);
相关问题
java编写求矩形的周长和面积
可以使用Java语言编写一个计算矩形周长和面积的程序,代码如下:
```java
import java.util.Scanner;
public class Rectangle {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("请输入矩形的长度:");
double length = input.nextDouble();
System.out.print("请输入矩形的宽度:");
double width = input.nextDouble();
double perimeter = 2 * (length + width); // 计算周长
double area = length * width; // 计算面积
System.out.println("矩形的周长是:" + perimeter);
System.out.println("矩形的面积是:" + area);
}
}
```
在上面的程序中,我们使用了`Scanner`类来获取用户输入的矩形的长度和宽度,然后根据周长和面积的公式计算出这两个值,并输出结果。
java计算矩形面积跟周长
以下是Java代码示例,可以计算矩形的面积和周长:
```java
import java.util.Scanner;
public class Rectangle {
public static void main(String[] args) {
int length, width;
Scanner scanner = new Scanner(System.in);
System.out.print("请输入矩形的长度:");
length = scanner.nextInt();
System.out.print("请输入矩形的宽度:");
width = scanner.nextInt();
// 计算面积
int area = length * width;
System.out.println("矩形的面积为:" + area);
// 计算周长
int perimeter = 2 * (length + width);
System.out.println("矩形的周长为:" + perimeter);
}
}
```
在该示例中,我们使用了 `Scanner` 类来获取用户输入的矩形长度和宽度,然后使用长度和宽度计算矩形的面积和周长。