c#Lesson03

...
using System;

namespace Day3
{
class MainClass
{
public static void Main (string[] args)
{
// 短路現(xiàn)象 邏輯運算符中 && (一假即假) ||(一真即真)
// //短路現(xiàn)象是一種 優(yōu)化
// int n = 10;
// bool b1 = 10 > 20 && 5 > ++n;
// Console.WriteLine (n);
// int n1
// = 10;
// bool b2 = 30 > 20 || 5 > ++n;
// Console.WriteLine (n1);

        // 編程中三種結構
        // 1. 順序結構
        // 2. 分支結構
        // 3. 循環(huán)結構(1)有事情做(2)有條件

        //死循環(huán)
        //          while(true){
        //              Console.WriteLine ("lanou");
        //          }

        // 如何控制循環(huán)
        // 控制循環(huán)的開始和結束
        // 如何控制循環(huán)次數(shù)
        // 3次
        // 記錄 循環(huán)次數(shù)(循環(huán)變量)
        //          int count = 0;
        //          // 循環(huán)條件 (count < 3),true 繼續(xù)循環(huán) false 結束循環(huán)
        //          while (count < 3) {
        //              Console.WriteLine ("lanou");
        //              // 循環(huán)增量
        //              count++;
        //          }
        //          int a = 0;
        //          while (a < 20) {
        //              Console.WriteLine (a);
        //              a++;
        //          }
        //打印10個 Hello World!
        //          int b = 0;
        //          while (b < 10) {
        //              Console.WriteLine ("Hello World!");
        //              b++;
        //          }
        //          int c = 0;
        //          while( c < 10){
        //              Console.WriteLine ("hello world!");
        //              c++;
        //          }
        //          int d = 0;
        //          while(d< 10){
        //              Console.WriteLine ("hello world");
        //              d++;
        //          }
        //          int h = 0;
        //          while (h < 10) {
        //              Console.WriteLine ("HelloWorld");
        //              h++;
        //          }
        // 打印0-9
        //          int count = 0;
        //          while (count < 10) {
        //              Console.WriteLine (count);
        //              count++;
        //          }
        //          int count = 0;
        //          while (count < 10) {
        //              Console.Write (count + 1);
        //              count++;
        //          }
        //          Console.WriteLine ();
        //          Console.WriteLine ();
        //打印 10-0
        //          int count = 11;
        //          while (count > 0) {
        //              Console.WriteLine (count - 1);
        //              count--;
        //          }
        // 輸入一個整數(shù),控制循環(huán)次數(shù)
        //          int loop = int.Parse (Console.ReadLine ());
        //          int count = 0;
        //          while (count < loop) {
        //              Console.Write (count + "\t");
        //              count++;
        //          }
        // 計算1~10的和五芝,并打印
        //          int sum = 0;
        //          // 保存和
        //          int count = 1;
        //          while (count <= 10) {
        //              sum += count;
        //              count++;
        //          }
        //          Console.WriteLine (sum);
        //
        //計算1-10的積
        //          int sum = 1;
        //          // 保存積
        //          int count = 1;
        //          while (count <= 10) {
        //              sum *= count;
        //              count++;
        //          }
        //          Console.WriteLine (sum);

        //          aMath f = new aMath ();
        //          f.add (10);
        //          Console.WriteLine (f);
        //  
        //打印 1 ~ 100之間所有的偶數(shù) 
        //          int n = 2;
        //          while (n <= 100) {
        //              
        //              Console.WriteLine (n);
        //              n += 2;
        //          }
        //          int count = 1;
        //          while (count <= 100) {
        //              if (count % 2 == 0) {
        //                  Console.WriteLine (count);
        //              }
        //              count++;
        //          }

        //計算 從 100 ~ 10000各個位之和為7的個數(shù)
        //自己想的方法
        //          int i = 100;
        //          int count = 0;
        //          while (i <= 10000) {
        //              int a = i % 10;
        //              int b = (i % 100 - a) / 10;
        //              int c = ((i % 1000) - (i % 100)) / 100;
        //              int d = ((i % 10000) - (i % 1000)) / 1000;
        //              if (a + b + c + d == 7) {
        //                  Console.WriteLine (i);
        //                  count++;
        //              }
        //              i++;
        //          }
        //          Console.WriteLine (count);
        //老師講的方法
        //          int count = 100;
        //          int temp = 0;
        //          while (count <= 10000) {
        //              //將各個位上的數(shù)拆分出來
        //              //保存和
        //              int result = 0;
        //              //三位
        //              if (count >= 100 && count <= 999) {
        //                  //百位
        //                  int n1 = count / 100;
        //                  //十位
        //                  int n2 = count % 100 / 10;
        //                  //個位
        //                  int n3 = count % 10;
        //                  // 將各個位上的和加起來
        //                  result = n1 + n2 + n3;
        //              } else if (count >= 1000 && count <= 9999) {
        //                  //千
        //                  int n1 = count / 1000;
        //                  int n2 = count % 1000 / 100;
        //                  int n3 = count % 100 / 10;
        //                  int n4 = count % 10;
        //                  result = n1 + n2 + n3 + n4;
        //              }
        //              //判斷 各個位上的和是否為7
        //              if (result == 7) {
        //                  Console.WriteLine (count);
        //                  temp++;
        //              }
        //
        //              count++;
        //          }
        //          Console.WriteLine (temp);
        //
        //          Console.WriteLine (temp);
        //          //又是一種算法啊苟呐,算法思想
        //          int num = 1234;
        //          int result = 0;
        //          int n2 = 1234 / 10; //12
        //          while (num != 0) {
        //              result += num % 10;
        //              num /= 10;
        //          }

        //          int count = 100;
        //          int num = 0;
        //          while (count >= 100 && count <= 10000) {
        //              //求加和
        //              int result = 0;
        //              //將count的值保存下來
        //              int temp = count;
        //              while (temp != 0) {
        //                  //取出個位
        //                  result += temp % 10;
        //                  //清除個位
        //                  temp /= 10;
        //              }
        //              //判斷是否==7;
        //              if (result == 7) {
        //                  Console.WriteLine (count);
        //                  num++;
        //              }
        //              count++;
        //          }
        //          Console.WriteLine (num);


        //
        //          int count = 0;
        //          while (count < 10) {
        //              Console.WriteLine (count);
        //              break;
        //              count++;
        //          }
        //          while (int.Parse (Console.ReadLine ()) != -1) {
        //              
        //          }
        //          while (true) {
        //              Console.WriteLine ("請輸入成績");
        //              int score = int.Parse (Console.ReadLine ());
        //              //當輸入是-1的時候停止循環(huán)
        //              if (score == -1) {
        //                  break;
        //              }
        //          }

        //如果while中嵌套了switch致板,那么
        //switch中的break昆稿,不會打斷循環(huán)
        //          while(true){
        //              switch(1){
        //              case 1:
        //                  break;
        //                  default:
        //                  break;
        //              }
        //          }
        //          bool b = true;
        //          while (b) {
        //              Console.WriteLine ("請輸入第一個數(shù):");
        //              int num1 = int.Parse (Console.ReadLine ());
        //              Console.WriteLine ("請輸入第二個數(shù)");
        //              int num2 = int.Parse (Console.ReadLine ());
        //              Console.WriteLine ("請輸入+-*/進行運算(輸入#退出)");
        //              switch (Console.ReadLine ()) {
        //              case "+":
        //                  Console.WriteLine (num1 + num2);
        //                  break;
        //              case "-":
        //                  Console.WriteLine (num1 - num2);
        //                  break;
        //              case "#":
        //                  b = !b;
        //                  break;
        //              default:
        //                  break;
        //              }

        //continue 只能使用在循環(huán)中
        //當循環(huán)
        //          int count = 0;
        //          while (count < 10) {
        //              Console.WriteLine (count);
        //              continue;
        //              count++;
        //          }
        //練習:打印從1-10中所有的偶數(shù)

        //          int count = 1;
        //          while (count <= 10) {
        //              if (count % 2 != 0) {
        //                  count++;
        //                  continue;
        //              }
        //              Console.WriteLine (count);
        //              count++;
        //          }
        //
        // do while
        //先執(zhí)行代碼辫封,在判斷條件
        //至少執(zhí)行一次代碼
        //除以上兩點侠碧,和while 沒有區(qū)別
        //          do {
        //              Console.WriteLine ("lanou");
        //          } while(false);
        //          int sum = 0;
        //          for (int i = 0; i <= 10; i++) {
        //              sum += i;
        //          }
        //          Console.WriteLine (sum);
        //





        int monye = 13;
        int year = monye * 320 * 60;
        Console.WriteLine (year);

    }

    //      class aMath
    //      {
    //          public int add (int n)
    //          {
    //              if (n > 1) {
    //                  return add (n - 1) + n;
    //              } else {
    //                  return 1;
    //              }
    //          }
    //      }
}

}
...

?著作權歸作者所有,轉載或內容合作請聯(lián)系作者
  • 序言:七十年代末抹估,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子弄兜,更是在濱河造成了極大的恐慌药蜻,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,470評論 6 501
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件替饿,死亡現(xiàn)場離奇詭異语泽,居然都是意外死亡,警方通過查閱死者的電腦和手機盛垦,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,393評論 3 392
  • 文/潘曉璐 我一進店門湿弦,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人腾夯,你說我怎么就攤上這事颊埃。” “怎么了蝶俱?”我有些...
    開封第一講書人閱讀 162,577評論 0 353
  • 文/不壞的土叔 我叫張陵班利,是天一觀的道長。 經(jīng)常有香客問我榨呆,道長罗标,這世上最難降的妖魔是什么? 我笑而不...
    開封第一講書人閱讀 58,176評論 1 292
  • 正文 為了忘掉前任积蜻,我火速辦了婚禮闯割,結果婚禮上,老公的妹妹穿的比我還像新娘竿拆。我一直安慰自己宙拉,他們只是感情好,可當我...
    茶點故事閱讀 67,189評論 6 388
  • 文/花漫 我一把揭開白布丙笋。 她就那樣靜靜地躺著谢澈,像睡著了一般。 火紅的嫁衣襯著肌膚如雪御板。 梳的紋絲不亂的頭發(fā)上锥忿,一...
    開封第一講書人閱讀 51,155評論 1 299
  • 那天,我揣著相機與錄音怠肋,去河邊找鬼敬鬓。 笑死,一個胖子當著我的面吹牛笙各,可吹牛的內容都是我干的钉答。 我是一名探鬼主播,決...
    沈念sama閱讀 40,041評論 3 418
  • 文/蒼蘭香墨 我猛地睜開眼酪惭,長吁一口氣:“原來是場噩夢啊……” “哼希痴!你這毒婦竟也來了?” 一聲冷哼從身側響起春感,我...
    開封第一講書人閱讀 38,903評論 0 274
  • 序言:老撾萬榮一對情侶失蹤砌创,失蹤者是張志新(化名)和其女友劉穎,沒想到半個月后鲫懒,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體嫩实,經(jīng)...
    沈念sama閱讀 45,319評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,539評論 2 332
  • 正文 我和宋清朗相戀三年窥岩,在試婚紗的時候發(fā)現(xiàn)自己被綠了甲献。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,703評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡颂翼,死狀恐怖晃洒,靈堂內的尸體忽然破棺而出慨灭,到底是詐尸還是另有隱情,我是刑警寧澤球及,帶...
    沈念sama閱讀 35,417評論 5 343
  • 正文 年R本政府宣布氧骤,位于F島的核電站,受9級特大地震影響吃引,放射性物質發(fā)生泄漏筹陵。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,013評論 3 325
  • 文/蒙蒙 一镊尺、第九天 我趴在偏房一處隱蔽的房頂上張望朦佩。 院中可真熱鬧,春花似錦庐氮、人聲如沸语稠。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,664評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至推沸,卻和暖如春输枯,著一層夾襖步出監(jiān)牢的瞬間议泵,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,818評論 1 269
  • 我被黑心中介騙來泰國打工桃熄, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留先口,地道東北人。 一個月前我還...
    沈念sama閱讀 47,711評論 2 368
  • 正文 我出身青樓瞳收,卻偏偏與公主長得像碉京,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子螟深,可洞房花燭夜當晚...
    茶點故事閱讀 44,601評論 2 353

推薦閱讀更多精彩內容

  • 知識點: 注:int類型默認32位有大小范圍 且第一位為符號位 0 為正 1 為負 8.4作業(yè) A:1谐宙、風力預警系...
    cGunsNRoses閱讀 1,096評論 0 0
  • using System; using System.Collections.Generic; using Sys...
    i_旅途閱讀 3,387評論 0 1
  • using System; class Person { // 一個字段不加訪問控制 默認是 private //...
    Class_Lee閱讀 261評論 0 0
  • 守望 --陶醉2017.3.12 一所老屋 如矗立三十多年的盾 我們躲在柜子后 我們蜷縮在角落 和四季捉迷...
    閑敲棋子Ray閱讀 214評論 0 1
  • 我還是很喜歡你 就像鴻雁在云垢箕,錦魚在水 愿你青衫薄袖 一笑望穿千年 我還是很喜歡你 就像三生石旁划栓,依依目光 愿你光...
    今心亦木閱讀 375評論 0 3