1.3代碼規(guī)范

2018-11-06 15:14 更新

“哦,說得沒錯(cuò),這個(gè)我以前聽老師說過,可是從來沒有在意過,我馬上改,改完再給你看看?!?/p>

class Program{

    static void Main(string[] args){
        try{
            Console.Write("請輸入數(shù)字A:");
            string strNumberA = Console.ReadLine();
            Console.Write("請選擇運(yùn)算符號(+、-、*、/):");
            string strOperate = Console.ReadLine();
            Console.Write("請輸入數(shù)字B:");
            string strNumberB = Console.ReadLine();
            string strResult = ;
            switch (strOperate){
                case "+":
                    strResult = Convert.ToString(Convert.ToDouble(strNumberA) 
                        + Convert.ToDouble(strNumberB));
                break;
                case "-":
                    strResult = Convert.ToString(Convert.ToDouble(strNumberA) 
                        - Convert.ToDouble(strNumberB));
                break;
                case "*":
                    strResult = Convert.ToString(Convert.ToDouble(strNumberA) 
                        * Convert.ToDouble(strNumberB));
                break;
                case "/":
                    if(strNumberB != 0){
                        strResult = Convert.ToString(Convert.ToDouble(strNumberA) / Convert.ToDouble(strNumberB));
                    }else{
                        strResult = 除數(shù)不能為0;
                        break;
                            }
                      }
                    Console.WriteLine(結(jié)果是: + strResult);
                    Console.ReadLine();
        
            }catch (Exception ex){
                Console.WriteLine(您的輸入有錯(cuò):+ ex.Message);
            }
         }
}

大鳥:“吼吼,不錯(cuò),不錯(cuò),改得很快嗎?至在目前代碼來說,實(shí)現(xiàn)計(jì)算器是沒有問題了,但這樣寫出的代碼是否合出題人的意思呢?”

小菜:“你的意思是面向?qū)ο螅?/p>

大鳥:“哈,小菜非小菜也!”

以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號