學習筆記(26):C#急速入門-bool相關練習題實戰

立即學習:https://edu.csdn.net/course/play/20589/257735?utm_source=blogtoedu

        //練習1:讓用戶輸入老蘇的語文和數學成績,輸出以下判斷是否正確,正確輸出True,錯誤輸出False
        //1)老蘇的語文和數學成績都大於90分
        //2)語文和數學有一門是大於90分的

          //Console.WriteLine("請輸入chinese成績:");
          //int chinese=Convert.ToInt32(Console.ReadLine());
          //Console.WriteLine("請輸入math成績:");
          //int math = Convert.ToInt32(Console.ReadLine());
          //Console.WriteLine("老蘇的語文和數學成績都大於90分:"+(chinese>90&&math>90));
          //Console.WriteLine("語文和數學有一門是大於90分的:" + (chinese > 90 || math > 90));
        
            
        //練習2:寫下判斷閏年的表達式,設待判斷的年份變量爲year.
        //潤年的判定(符合下面兩個條件之一):
        //年份能夠被400整除.(2000)
        //年份能夠被4整除但不能被100整除.(2008)
        //讓用戶輸入一個年份,如果是潤年,則輸出true,如果不是,則輸出false.
          Console.WriteLine("請輸入年份:");
          int year = Convert.ToInt32(Console.ReadLine());
          bool t1 = year % 400 == 0;
          bool t2 =(year%4==0)&&(year%100!=0);
                                    
          Console.WriteLine("輸入的年份是否爲閏年"+(t1||t2));
                                
          Console.ReadKey();

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章