小和尚要挑幾次水才可以把水缸挑滿?分別使用while和do while實現
阿新 • • 發佈:2019-02-16
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
classProgram
{
staticvoid Main(string[]args)
{
intamount = 35,i=0;
while(amount >0)
{
amount -= 5;
++i;
}
Console.WriteLine(i);
}
}
}
(2)
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
classProgram
{
staticvoid Main(string[]args)
{
int amount = 35,i=0;
do
{
amount -= 5;
++i;
} while (amount > 0);
Console.WriteLine(i);
}
}
}