当前位置:网站首页>流程控制任务
流程控制任务
2022-06-27 19:20:00 【continueLR】
目录
XZK-JavaEE 技术方向-10101003-选择结构训练任务
1、某市出租车,起步价(2 公里以内)为 8 元,超过 2 公里的按照每公里 4.5 元计算。要求根据路程计算费用。
3、要求输入月份,判断该月所处的季节并输出季节(假设:12、1、2 月为冬季,依次类推)
XZK-JAVA-支线任务-010103-002- 流程控制的逻辑训练任务(分支+循环综合)
3、图形打印任务在控制台中,编写三个 Demo,分别输出如下图形:
5、打印三位数中的所有水仙花数所谓“水仙花数”即一个整数满足其值等于各个数位的立方和。如: 153 是一个水仙花数,因为 153= 1³+5³+3³
人工智能的概念刚兴起时,网上流传了一段价值一个亿的代码,如下图
XZK-JavaEE 技术方向-10101003-选择结构训练任务
1、某市出租车,起步价(2 公里以内)为 8 元,超过 2 公里的按照每公里 4.5 元计算。要求根据路程计算费用。
public static void main(String[] args) {
System.out.println("请输入路程为:");
Scanner input = new Scanner(System.in);
double s = input.nextDouble();
if(s<=0) {
System.out.println("你输入的路程是个锤子");
}else if(s<2){
System.out.println("路程计算费用为8元");
}else{
System.out.println("路程计算费用为"+s*4.5+"元");
}
}
}
2、输入年份,判断输入的年份是否是闰年。(闰年的条件是能被 4 整除,但不能被 100 整除;或能被 400 整除。)
public static void main(String[] args) {
System.out.println("请输入年份:");
Scanner input = new Scanner(System.in);
int i = input.nextInt();
if (i%4==0&&i%100!=0||i%400==0) {
System.out.println("你输入的是闰年");
}else {
System.out.println("你输入的不是闰年");
}
}
}
3、要求输入月份,判断该月所处的季节并输出季节(假设:12、1、2 月为冬季,依次类推)
public static void main(String[] args) {
System.out.println("请输入月份:");
Scanner input = new Scanner(System.in);
int i = input.nextInt();
switch(i) {
case 12:
case 1:
case 2:
System.out.println("冬季");
break;
case 3:
case 4:
case 5:
System.out.println("春季");
break;
case 6:
case 7:
case 8:
System.out.println("夏季");
break;
case 9:
case 10:
case 11:
System.out.println("秋季");
break;
default:
System.out.println("你输入的不是月份");
break;
}
}
}4、根据《国家电网销售电价表》,居民生活用电按 3 个梯度收费:月用电量 150 千瓦时及以下部分,每千瓦时 0.43 元,151—400 千瓦时部分为 0.45元,401 千瓦时以上部分为 0.52 元,请编写程序,当输入用户的用电量时,计算出所需付的费用。
public static void main(String[]args) {
System.out.println("请输入用户用电量:");
Scanner input = new Scanner(System.in);
int i =input.nextInt();
if(i<0) {
System.out.println("你输入的用户用电量有误");
}else if (i<=150) {
System.out.println("你输入的用户用电量为"+i*0.43+"元");
}else if(i<=400) {
System.out.println("你输入的用户用电量为"+i*0.45+"元");
}else
System.out.println("你输入的用户用电量为"+i*0.52+"元");
}
}
XZK-JAVA-支线任务-010103-002- 流程控制的逻辑训练任务(分支+循环综合)
1、计算应缴金额
商场根据会员积分打折:
2000 分以内打 9 折,
4000 分以内打 8 折,
8000 分以内打 7.5 折,
8000 分以上打 7 折, 使用 if-else-if 结构,实现手动输入购物金额和积分,计算出应缴金额
public static void main(String[] args) {
System.out.println("请输入会员积分:");
Scanner input = new Scanner(System.in);
int i = input.nextInt();
if(i<0) {
System.out.println("您输入的积分有误");
}else if(i<2000) {
System.out.println("应缴金额为"+i*0.90+"元");
}else if(i<4000) {
System.out.println("应缴金额为"+i*0.80+"元");
}else if(i<8000) {
System.out.println("应缴金额为"+i*0.75+"元");
}else {
System.out.println("应缴金额为"+i*0.70+"元");
}
}
}2、计算该年该月天数
一年中有 12 个月,而每个月的天数是不一样的。其中大月 31 天,分别为1,3,5,7,8,10,12 月,小月 30 天,分别 为 4,6,9,11 月。还有二月比较特殊,平年的二月只有 28 天,而闰年的二月有 29 天,由用户在控制台输入年月日,程序计算输入的日期是当年的第多少天。 (例如输入 2000 年 12 月 31 日,应该输出是第 366 天)。
public static void main(String[] args) {
System.out.println("请输入年份和月份");
Scanner input = new Scanner(System.in);
int year = input.nextInt();
int mouth = input.nextInt();
switch(mouth){
case 1:case 3: case 5: case 7: case 8: case 10: case 12:
System.out.println("本月有31天");
break;
case 4: case 6 :case 9 :case 11:
System.out.println("本月有30天");
break;
case 2:
if(year%4==0&&year%100!=0||year%400==0){
System.out.println("本月有29天");
}
else{
System.out.println("本月有28天");
}
break;
}
}
}3、图形打印任务
在控制台中,编写三个 Demo,分别输出如下图形:

public static void main(String[]args) {
for(int i =0;i<5;i++) {
for(int j =0;j<i+1;j++) {
System.out.print("*");
}
System.out.println();
}
}
}
public static void main(String[] args) {
for(int i =0;i<5;i++) {
for(int j =0;j<5-i;j++) {
System.out.print("*");
}
System.out.println();
}
}
}

public static void main(String[] args) {
for(int i =0;i<5;i++) {
for(int j=0;j<4-i;j++) {
System.out.print(" ");
}
for(int j=0;j<i*2+1;j++) {
System.out.print("*");
}
System.out.println();
}
}
}
4、打印九九乘法表 ,效果如图:

public static void main(String[] args) {
System.out.println("九九乘法表");
for(int i=0;i<10;i++) {
for(int j=1;j<i+1;j++) {
System.out.print(j+"*"+i+"="+j*i+" ");
}
System.out.println();
}
}
}5、打印三位数中的所有水仙花数
所谓“水仙花数”即一个整数满足其值等于各个数位的立方和。
如: 153 是一个水仙花数,因为 153= 1³+5³+3³
public static void main(String[] args) {
for(int i=100;i<1000;i++) {
int ge =i%10;
int shi=i/10%10;
int bai=i/100%10;
if(ge*ge*ge+shi*shi*shi+bai*bai*bai==i) {
System.out.println(i);
}
}
}
}
人工智能的概念刚兴起时,网上流传了一段价值一个亿的代码,如下图

边栏推荐
- 爱数课实验 | 第六期-金融反欺诈案例研究
- Navicat premium connection problem --- host 'XXXXXXXX' is not allowed to connect to this MySQL server
- GFS distributed file system
- # Leetcode 821. Minimum distance of characters (simple)
- This is the same as data collection. Can you define a parameter as last month or the previous day, and then use this parameter in SQL?
- PCIE知识点-008:PCIE switch的结构
- MySQL usage notes 1
- Cerebral Cortex:从任务态和静息态脑功能连接预测儿童数学技能
- Ceph分布式存储
- SQL必需掌握的100个重要知识点:使用函数处理数据
猜你喜欢

快递e栈——数组篇小型项目

体验Navicat Premium 16,无限重置试用14天方法(附源码)

A set of system to reduce 10 times the traffic pressure in crowded areas

Model reasoning acceleration based on tensorrt

Kirin V10 installation font

BTC and eth recapture the lost land! Leading the market recovery? Encryption will enter the "ice age"!

抖音的兴趣电商已经碰到流量天花板?

Use the storcli tool to configure raid. Just collect this article

Squid proxy server

Graduation design of police report convenience service platform based on wechat applet
随机推荐
2021全球独角兽榜发布:中国301家独角兽企业全名单来了!
抖音的兴趣电商已经碰到流量天花板?
Kirin V10 installation font
DO280OpenShift访问控制--security policy和章节实验
OpenSSL 编程 一:基本概念
ARCS模型介绍
White whoring red team goby & POC, how do you call white whoring?
SQL必需掌握的100个重要知识点:组合 WHERE 子句
MySQL client tools are recommended. I can't imagine that it is best to use Juran
Flexible IP network test tool -- x-launch
Love math experiment | phase VI - Financial anti fraud case study
Codeforces Global Round 14
Experiment of love number lesson | phase V - emotion judgment of commodity review based on machine learning method
Flask----应用案例
爱数课实验 | 第九期-利用机器学习方法进行健康智能诊断
爱数课实验 | 第六期-金融反欺诈案例研究
Save method of JPA stepping pit series
100 important knowledge points that SQL must master: creating calculation fields
请教CMS小程序首页的幻灯片在哪里设置?
A set of system to reduce 10 times the traffic pressure in crowded areas