while、do while练习——7月24日
生活随笔
收集整理的這篇文章主要介紹了
while、do while练习——7月24日
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
while循環的格式是for循環的變形
//while 循環(當循環),是for循環的變形//for(int i=0;i<=5;i++)//{// Console.WriteLine("hello!");//}//Console.ReadLine();//還可以寫成//int i = 0;//for (; i <= 5; )//{// Console.WriteLine("hello!");// i++;//}//Console.ReadLine();//while 格式//int i = 0;//while (i <= 5)//{// Console.WriteLine("hello!");// i++;//}//Console.ReadLine();//do while 格式 int i = 0;do//不管后面的判斷對不對,先執行了再說 {Console.WriteLine("hello!");} while (i < 5);Console.ReadLine();練習一:用while循環計算折紙次數
//一張紙厚度為0.07毫米,問對折多少次至少超過8848米//8848米=8848000毫米//int sum = 0;//double h = 0.07;//while (h < 8848000)//{// h *= 2;// sum++;//}//Console.WriteLine("至少需要折疊"+sum+"次。");//Console.ReadLine();//方法2:int sum = 0;double h= 0.07;while (1 == 1)//死循環 { h *= 2;sum++;Console.WriteLine("第" + sum + "次的高度是:" + h / 1000 + "米。");if (h >= 8848000){break;//結束整個循環,并跳出循環;continue是結束本次循環,繼續下次循環 } }Console.WriteLine("至少需要折疊" + sum + "次。");Console.ReadLine();?
練習二:用while打印九九口訣表
//用while循環打印99口訣表int i = 1;while (i <= 9)//打印行 { int j = 1;while (j <= i)//打印列 { Console.Write(j+"*"+i+"="+j*i+"\t");j++; } i++;Console.WriteLine();} Console.ReadLine();?
轉載于:https://www.cnblogs.com/juyangchao12/p/5701940.html
總結
以上是生活随笔為你收集整理的while、do while练习——7月24日的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java Spring MVC
- 下一篇: 调试接口API