当前位置:网站首页>流程控制任务
流程控制任务
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);
}
}
}
}
人工智能的概念刚兴起时,网上流传了一段价值一个亿的代码,如下图

边栏推荐
- BTC and eth recapture the lost land! Leading the market recovery? Encryption will enter the "ice age"!
- 爱数课实验 | 第八期-新加坡房价预测模型构建
- Squid proxy server
- 100 important knowledge points for SQL: in operator
- 爱数课实验 | 第九期-利用机器学习方法进行健康智能诊断
- 富文本 考试 填空题
- Navicat premium connection problem --- host 'XXXXXXXX' is not allowed to connect to this MySQL server
- 华为伙伴暨开发者大会2022开源时刻全纪录
- Covering access to 2w+ traffic monitoring equipment, EMQ creates a new digital engine for all elements of traffic in Shenzhen
- Codeforces Round #717 (Div. 2)
猜你喜欢

SQL server for circular usage

Flexible IP network test tool -- x-launch

Codeforces Round #716 (Div. 2)

Ceph分布式存储

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

于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日

Model reasoning acceleration based on tensorrt

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

Very comprehensive dolphin scheduler installation and use documents

Zhongang Mining: the largest application field of new energy or fluorite
随机推荐
Share how I take notes
MySQL速成——第一天--基础入门
GoLand permanently activated
覆盖接入2w+交通监测设备,EMQ 为深圳市打造交通全要素数字化新引擎
Leetcode 821. Minimum distance of characters (simple) - sequel
非常全面的DolphinScheduler(海豚调度)安装使用文档
1029 Median
爱数课实验 | 第七期-基于随机森林的金融危机分析
Data platform scheduling upgrade and transformation | operation practice from Azkaban smooth transition to Apache dolphin scheduler
Shell command used in actual work - sed
Show the comprehensive strength of strong products, and make the first show of 2022 Lincoln aviator in Southwest China
华为伙伴暨开发者大会2022开源时刻全纪录
Here are 12 commonly used function formulas for you. All used ones are good
Codeforces Round #716 (Div. 2)
Original translation | comparison of machine learning model service tools: kserve, Seldon core and bentoml
Is it safe to open an account and buy stocks on the Internet? New to stocks, no guidance
展现强劲产品综合实力 ,2022 款林肯飞行家Aviator西南首秀
Experiment of love number lesson | phase V - emotion judgment of commodity review based on machine learning method
Cerebral Cortex:从任务态和静息态脑功能连接预测儿童数学技能
Codeforces Round #719 (Div. 3)