分支语句嵌套练习
練習
1、男士體重 = 身高 - 100 (+-3)
女士體重 = 身高 - 110 (+-3)
請輸入性別:
請輸入體重(kg):
請輸入身高(cm):
您的體重非常標準/您需要減肥了/您需要補充營養
您距離標準體重還差xxx公斤
?
using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace 分支語句嵌套練習1 {class Program{static void Main(string[] args){Console.Write("請輸入性別:(男/女)");string a = Console.ReadLine();Console.Write("請輸入體重:(公斤)");decimal t = Convert.ToDecimal(Console.ReadLine());Console.Write("請輸入身高:(厘米)");decimal g = Convert.ToDecimal(Console.ReadLine());string n = "男";if (n == a){ if ((t == g - 100) || (t == g - 101) || (t == g - 102) || (t == g - 103) || (t == g - 99) || (t == g - 98) || t == g - 97){Console.Write("您的體重非常標準了");}else if (t < g - 103){Console.Write("您需要補充營養了,你距離標準體重還差" + (g - 103 - t) + "公斤");}else if (t > g - 97){Console.Write("您需要減肥了,你距離標準體重還差" + (t - (g - 97) ) + "公斤");}}else{if ((t == g - 110) || (t == g - 111) || (t == g - 112) || (t == g - 113) || (t == g - 109) || (t == g - 108) || t == g - 107){Console.Write("您的體重非常標準了");}else if (t < g - 113){Console.Write("您需要補充營養了,你距離標準體重還差" + (g - 113 - t) + "公斤");}else if (t > g - 107){Console.Write("您需要減肥了,你距離標準體重還差" + (t - (g - 107) ) + "公斤");}}//身高-100(+—3) b=g-100(+-3)//您的體重非常標準了 您需要減肥了 您需要補充營養了//你距離標準體重還差xx公斤 Console.ReadLine();}} }?
2、24時轉為12時
讓用戶輸入一個 24時制的時間,比如:
請輸入小時: 14
請輸入分鐘: 33
?
using System; using System.Collections.Generic; using System.Linq; using System.Text;namespace 練習二 {class Program{static void Main(string[] args){Console.Write("請輸入小時:");int xh = Convert.ToInt32(Console.ReadLine());Console.Write("請輸入分鐘:");int fz = Convert.ToInt32(Console.ReadLine());if (xh >= 0 && xh < 24){if (fz >= 0 && fz < 60){if (xh > 12){Console.Write("下午"+(xh-12)+":"+fz);}else {Console.Write("上午"+xh+":"+fz);}}else {Console.WriteLine("分鐘輸入錯誤!");}}else {Console.WriteLine("小時輸入錯誤!");}Console.ReadLine();//24時轉為12時 請輸入一個24時制的時間 請輸入小時: 請輸入分鐘: }} }?
轉載于:https://www.cnblogs.com/songfengyao/p/5515244.html
總結
- 上一篇: 苹果iPhone应该刷哪个版本固件好?
- 下一篇: java 接口练习题1