關(guān)于for循環(huán)和while循環(huán)的轉(zhuǎn)換
static void Main(string[] args)
??????? {
??????????? for (int y = 1; y <= 7; y++)
??????????? {
??????????????? for (int x = 1; x <= y; x++)
??????????????? {
??????????????????? Console.Write(x);
??????????????? }
??????????????? Console.WriteLine();//換行
??????????? }
??????? }
第二個(gè)for循環(huán)能改成while循環(huán)嗎?本人愚拙,望大神賜教。
2018-05-21
for (int y = 1; y <= 7; y++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for (int x = 1; x <= 7; x++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if(x<=y)
? ? ? ? ? ? ? ? ? ? Console.Write(x);
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Console.WriteLine();//換行
? ? ? ? ? ? }
2018-04-25
可以改但是得先聲明變量x
static void Main(string[] args)
??????? {
? ? ? ? ? ? int x = 1
????????????for (int y = 1; y <= 7; y++)
??????????? {
??????????????? while(x <= y)
??????????????? {
??????????????????? Console.Write(x);
????????????????????x++:
??????????????? }
??????????????? Console.WriteLine();//換行
??????????? }
??????? }