import java.util.Scanner;
public class Area {
public static void main(String[] args) {
// TODO Auto-generated method stub
double PI = 3.14;
System.out.println("1 矩形 2 三角形 3 圆");
System.out.print("请选择图形:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
do {
if (n == 1) {
System.out.print("请输入矩形的宽:");
int acreage = sc.nextInt();
System.out.print("请输入矩形的高:");
int hight = sc.nextInt();
float area = acreage * hight;
System.out.println("该矩形的面积为:" + area);
} else if (n == 2) {
System.out.print("请输入三角形的的底:");
int low = sc.nextInt();
System.out.print("请输入三角形的高:");
int hight = sc.nextInt();
float area = low * hight / 2;
System.out.println("该三角形的面积为:" + area);
} else if (n == 3) {
System.out.print("请输入圆的的半径:");
int radius = sc.nextInt();
double area = PI * radius * radius;
System.out.println("该圆的面积为:" + area);
}
else {
System.out.println("输入错误!!!");
}
System.out.print("请选择图形:");
n = sc.nextInt();
} while (true);
}
}
public class Area {
public static void main(String[] args) {
// TODO Auto-generated method stub
double PI = 3.14;
System.out.println("1 矩形 2 三角形 3 圆");
System.out.print("请选择图形:");
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
do {
if (n == 1) {
System.out.print("请输入矩形的宽:");
int acreage = sc.nextInt();
System.out.print("请输入矩形的高:");
int hight = sc.nextInt();
float area = acreage * hight;
System.out.println("该矩形的面积为:" + area);
} else if (n == 2) {
System.out.print("请输入三角形的的底:");
int low = sc.nextInt();
System.out.print("请输入三角形的高:");
int hight = sc.nextInt();
float area = low * hight / 2;
System.out.println("该三角形的面积为:" + area);
} else if (n == 3) {
System.out.print("请输入圆的的半径:");
int radius = sc.nextInt();
double area = PI * radius * radius;
System.out.println("该圆的面积为:" + area);
}
else {
System.out.println("输入错误!!!");
}
System.out.print("请选择图形:");
n = sc.nextInt();
} while (true);
}
}