日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程资源 > 编程问答 >内容正文

编程问答

分支嵌套

發(fā)布時(shí)間:2025/3/15 编程问答 13 豆豆
生活随笔 收集整理的這篇文章主要介紹了 分支嵌套 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

練習(xí)1

男士體重 = 身高 - 100 (+-3)
女士體重 = 身高 - 110 (+-3)
請(qǐng)輸入性別:
請(qǐng)輸入體重(kg):
請(qǐng)輸入身高(cm):

您的體重非常標(biāo)準(zhǔn)/您需要減肥了/您需要補(bǔ)充營(yíng)養(yǎng)

您距離標(biāo)準(zhǔn)體重還差xxx公斤

//輸入性別,體重和身高,判斷是否是標(biāo)準(zhǔn)體重,不是那相差多少公斤,你的體重很標(biāo)準(zhǔn)/你需要減肥啦/你需要補(bǔ)充營(yíng)養(yǎng)//用戶(hù)輸入性別,體重升高Console.Write("請(qǐng)輸入性別(男/女):");string a = Console.ReadLine();Console.Write("請(qǐng)輸入體重(kg):");decimal b = Convert.ToDecimal(Console.ReadLine());Console.Write("請(qǐng)輸入身高(cm):");decimal c = Convert.ToDecimal(Console.ReadLine());//判斷是否是標(biāo)準(zhǔn)體重并打印//男:體重=身高-100(+-3)// b =c-100(+-3) //女:體重=身高-110(+-3)//b=c-100(+-3)if (a == "")//判斷是男是女 {decimal d = b - (c - (100));//與標(biāo)準(zhǔn)體重相差的if (d>3){Console.WriteLine("你需要減肥啦!");Console.WriteLine("與標(biāo)準(zhǔn)體重相差:"+(d-3)+"kg");}else if (d<-3){Console.WriteLine("你需要補(bǔ)充營(yíng)養(yǎng)!");Console.WriteLine("與標(biāo)準(zhǔn)體重相差:" +( d+3) + "kg");}else if(d>=-3&&d<=3){Console.WriteLine("你的體重非常標(biāo)準(zhǔn)!");}}else{decimal d = b - (c - 110);if (d>3){Console.WriteLine("你需要減肥啦!");Console.WriteLine("與標(biāo)準(zhǔn)體重相差:" + (d-3) + "kg");}else if (d<-3){Console.WriteLine("你需要補(bǔ)充營(yíng)養(yǎng)!");Console.WriteLine("與標(biāo)準(zhǔn)體重相差:" + (d+3) + "kg");}else if (d>=-3&&d<=3){Console.WriteLine("你的體重非常標(biāo)準(zhǔn)!");}}Console.Read();

運(yùn)算結(jié)果

練習(xí)2

讓用戶(hù)輸入年齡,如果小于18歲,那么提示“少兒不宜,你不能查看。”
如果大于18歲,那么提示“你可以查看,是否要看?(yes/no):”
當(dāng)用戶(hù)輸入yes時(shí),輸出“查看成功”,否則輸出“用戶(hù)取消查看”。

//輸入用戶(hù)年齡,判斷是否大于18。如果大于,是否要看//輸入用戶(hù)年齡Console.Write("請(qǐng)輸入年齡:");decimal age = Convert.ToDecimal(Console.ReadLine());//判斷是否滿(mǎn)18歲if (age >= 18)//是否大于18歲 {Console.Write("你可以查看,是否查看(yes / no):");//確定滿(mǎn)十八歲string b = Console.ReadLine();if (b=="yes")//是否查看 {Console.WriteLine("查看成功!");}else{Console.WriteLine("用戶(hù)取消查看。");}}else //不滿(mǎn)十八歲 {Console.WriteLine("少兒不宜,你不能查看。");}Console.ReadLine();

運(yùn)算結(jié)果

練習(xí)3

24時(shí)轉(zhuǎn)為12時(shí)
讓用戶(hù)輸入一個(gè) 24時(shí)制的時(shí)間,比如:
請(qǐng)輸入小時(shí): 14
請(qǐng)輸入分鐘: 33

打印的結(jié)果為: 下午2點(diǎn)33分

//24時(shí)轉(zhuǎn)為12時(shí),小時(shí)不能為負(fù)數(shù),不能超過(guò)24.分鐘不能為負(fù)數(shù),不能超過(guò)60//用戶(hù)輸入一個(gè)24時(shí)制得時(shí)間 Console.Write("請(qǐng)輸入小時(shí):");int a = Convert.ToInt32(Console.ReadLine());Console.Write("請(qǐng)輸入分鐘:");int b = Convert.ToInt32(Console.ReadLine());//判斷是否輸入錯(cuò)誤,并打印if (a >= 0 && a < 24 )//小時(shí)輸入正確 {if (b > 0 && b < 60)//分鐘輸入正確 {if (a <= 12){Console.WriteLine("上午"+a + "點(diǎn):" + b + "分。");}else{int c = a - 12;Console.WriteLine("下午"+c + "點(diǎn):" + b + "分。");}}else{Console.WriteLine("分鐘輸入錯(cuò)誤!");}}else{Console.WriteLine("小時(shí)輸入錯(cuò)誤!");}Console.ReadLine();

運(yùn)算結(jié)果

練習(xí)4

讓用戶(hù)輸入兩個(gè)數(shù),再讓用戶(hù)輸入一個(gè)運(yùn)算符,然后輸出運(yùn)算的結(jié)果

//輸入兩個(gè)數(shù),再輸入一個(gè)運(yùn)算符,然后輸出結(jié)果//用戶(hù)輸出兩個(gè)數(shù)Console.Write("請(qǐng)輸入第一個(gè)數(shù):");decimal a = Convert.ToDecimal(Console.ReadLine());Console.Write("請(qǐng)輸入第一個(gè)數(shù):");decimal b = Convert.ToDecimal(Console.ReadLine());Console.Write("請(qǐng)輸入一個(gè)運(yùn)算符:");string c = Console.ReadLine();//輸入一個(gè)運(yùn)算符if (c == "+" || c == "-" || c == "*" || c == "/" || c == "%"){if (c == "+"){Console.WriteLine(a+b);}else if (c == "-"){Console.WriteLine(a-b);}else if (c == "*"){Console.WriteLine(a*b);}else if (c == "/"){Console.WriteLine(a / b);}else if (c == "%"){Console.WriteLine(a % b);}}else{Console.WriteLine("輸入錯(cuò)誤");}Console.ReadLine();

?

運(yùn)算結(jié)果

練習(xí)5

你有房子嗎?有,那結(jié)婚吧,沒(méi)有,你有錢(qián)嗎?有,先買(mǎi)房再結(jié)婚吧,沒(méi)有,你又能力嗎?有,先賺錢(qián)再買(mǎi)房再結(jié)婚吧,沒(méi)有拜拜

//輸入你有房嗎?有,那結(jié)婚吧。沒(méi)有,那你有錢(qián)嗎?有,那你先買(mǎi)房。沒(méi)有,那你有能力嗎?有,先賺錢(qián)再買(mǎi)房再結(jié)婚,沒(méi)有,拜拜//用戶(hù)輸入Console.Write("你有房嗎?(有/沒(méi)有)");string a = Console.ReadLine();//判斷,輸出if (a == "")//有房 {Console.WriteLine("那結(jié)婚吧。");}else{Console.Write("你有錢(qián)嗎?");string b = Console.ReadLine();if (b == "")//有錢(qián) {Console.WriteLine("先買(mǎi)房再結(jié)婚吧。");}else{Console.Write("那你有能力嗎?");string c = Console.ReadLine();if (c == "")//有能力 {Console.WriteLine("那先賺錢(qián)再買(mǎi)房再結(jié)婚吧。");}else{Console.WriteLine("拜拜");}}}Console.ReadLine();

運(yùn)算結(jié)果

練習(xí)6

?讓用戶(hù)輸入日期,判斷輸入的日期是否正確

0-9999,月1-12,日按照月份來(lái),需要判斷閏年 //輸入日期,判斷日期是否正確//用戶(hù)輸入Console.Write("請(qǐng)輸入年:");int a =Convert.ToInt32(Console.ReadLine());Console.Write("請(qǐng)輸入月份:");int b = Convert.ToInt32(Console.ReadLine());Console.Write("請(qǐng)輸入日期:");int c = Convert.ToInt32(Console.ReadLine());//判斷是否正確//1-9999//能被4整除的大部分是閏年,能被100整除而不能被400整除的不是閏年,能被3200整除的不是閏年int d = a % 4, e=a%100, f =a%400, s=a%3200;if (a > 0 && a <= 9999)//年份輸入正確 {if (d != 0&& e != 0 && f != 0 || s == 0)//不是閏年 {if (b > 0 && b < 12)//月份輸入正確 {if ((c < 0) || (b == 2 && c > 28)|| ((b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12) && (c > 31))|| ((b == 4 || b == 6 || b == 9 || b == 11) && (c > 30)))//日期輸入不正確 {Console.WriteLine("日期輸入錯(cuò)誤");}else{Console.WriteLine("你輸?shù)娜掌谑?#xff1a;" + a + "" + b + "" + c + "");}}else{Console.WriteLine("月份輸入錯(cuò)誤");}}else{if (b > 0 && b < 12)//月份輸入正確 {if ((c < 0) || (b == 2 && c > 29)|| ((b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12) && (c > 31))|| ((b == 4 || b == 6 || b == 9 || b == 11) && (c > 30)))//日期輸入錯(cuò)誤 {Console.WriteLine("日期輸入錯(cuò)誤");}else{Console.WriteLine("你輸?shù)娜掌谑?#xff1a;" + a + "" + b + "" + c + "");}}else{Console.WriteLine("月份輸入錯(cuò)誤");}}}else{Console.WriteLine("年份輸入錯(cuò)誤");}Console.ReadLine();

運(yùn)算結(jié)果

?

轉(zhuǎn)載于:https://www.cnblogs.com/sunshuping/p/5515330.html

新人創(chuàng)作打卡挑戰(zhàn)賽發(fā)博客就能抽獎(jiǎng)!定制產(chǎn)品紅包拿不停!

總結(jié)

以上是生活随笔為你收集整理的分支嵌套的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。