循环——面积循环版
来源:互联网 发布:nginx etag 配置 编辑:程序博客网 时间:2024/06/05 11:43
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);
}
}
0 0
- 循环——面积循环版
- “增强版”for循环 —— for each循环
- 循环结构语句——For循环
- 循环结构语句——while循环
- 基础知识—循环语句-循环控制
- Python——循环
- Python——循环
- 【C#】—循环语句
- 第七周—循环
- Javascript—循环
- 数据结构—循环队列
- Javase—循环语句
- 循环
- 循环
- 循环
- 循环
- 循环
- 循环
- VMware 11.0 简体中文版|附永久密钥
- 树莓派增加apt-get下载源的方法
- syslog函数详解 http://blog.chinaunix.net/uid-10540984-id-3506091.html
- MySQL优化
- jsp小后门
- 循环——面积循环版
- 计算机网络之面试常考
- AngularJS的digest循环和$apply
- [leetcode] 10.Regular Expression Matching
- 文本、日期、数字的连接
- Java中有关Null的9件事
- HDU 2708 模拟
- Spring与Struts区别联系
- 树莓派软件更新