for循环语句
- ***** 第一行 5 0个空格
***** 第二行 5 1个空格
***** 第三行 5 2个空格
***** 第四行 5 3个空格
***** 第五行 5 4个空格
//i的for循环控制换行,i就可以代表行号
for (int i = 0; i < 5; i++)
{
for (int k = 0; k < i; k++)
{
Console.Write(" ");
}
for (int j = 0; j < 5; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
***
****
*****
for (int i = 0; i < 5; i++)
{
for (int j = 0; j <=i ; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
3. *
**
***
****
*****
for (int i = 0; i < 5; i++)
{
for (int k = 0; k < 5-i-1; k++)
{
Console.Write(" ");
}
for (int j = 0; j <=i ; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
**
*
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 5-i; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
5.*****
****
***
**
*
for (int i = 0; i < 5; i++)
{
for (int k = 0; k < i; k++)
{
Console.Write(" “);
}
for (int j = 0; j < 5-i; j++)
{
Console.Write(”*");
}
Console.WriteLine();
}
6. *
***
*****
*******
for (int i = 1; i <= 5; i++)
{
for (int k = 0; k < 5-i; k++)
{
Console.Write(" ");
}
for (int j = 0; j < i*2-1; j++)
{
Console.Write("*");
}
Console.WriteLine();
}
7.*****
*****
for (int i = 0; i < 5; i++)
{
for (int k = 0; k < i; k++)
{
Console.Write(" ");
}
for (int j = 0; j < 5; j++)
{
if (i==0||i==4)
{
Console.Write("*");
}
else
{
Console.Write((j==0||j==4)?"*":" ");
}
}
Console.WriteLine();
}
***
***
*
for (int i = 0; i <=9; i++)
{
if (i<5)
{
for (int k = 0; k < 5 - i - 1; k++)
{
Console.Write(" ");
}
for (int j = 0; j < i * 2 + 1; j++)
{
Console.Write("*");
}
}
else
{
for (int k = 0; k < i-4; k++)
{
Console.Write(" ");
}
for (int j = 0; j < (9-i)*2-1; j++)
{
Console.Write("*");
}
}
Console.WriteLine();
}
9.99乘法表
//方法一
for (int i = 1; i < 10; i++)
{
for (int j = 1; j <=i; j++)
{
Console.Write(j+""+i+"="+ij+"\t");
}
Console.WriteLine();
}
//方法二
for (int i = 1; i < 10; i++)
{
for (int j = 1; j <=i; j++)
{
Console.Write("{0}{1}={2}{3}",j,i,ij,(ij>9?" “:” “));
}
Console.WriteLine();
}
//方法一
for (int i = 1; i < 10; i++)
{
for (int j = 1; j <=i; j++)
{
Console.Write(j+”"+i+"="+ij+"\t");
}
Console.WriteLine();
}
//方法二
for (int i = 1; i < 10; i++)
{
for (int j = 1; j <=i; j++)
{
Console.Write("{0}{1}={2}{3}",j,i,ij,(ij>9?" “:” "));
}
Console.WriteLine();
}
10. *****
*******
*********
***********
*********
*********
*********
*********
for (int i = 0; i < 9; i++)
{
if (i<5)
{
for (int k = 0; k < 5 - i-1; k++)
{
Console.Write(" ");
}
for (int j = 0; j < i * 2 + 5; j++)
{
Console.Write("*");
}
}
else
{
for (int k = 0; k < 2; k++)
{
Console.Write(" ");
}
for (int j = 0; j < 9; j++)
{
Console.Write("*");
}
}
Console.WriteLine();
}
11.控制台的点餐系统
static void Main(string[] args)
{
int count = 0;
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("欢迎来到【英莱特】餐厅");
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("======================");
Console.ForegroundColor = ConsoleColor.Cyan;
Console.WriteLine("1.土豆丝 12元");
Console.WriteLine("2.拍黄瓜 10元");
Console.WriteLine("3.红烧肉 28元");
Console.WriteLine("4.水煮肉 30元");
Console.ForegroundColor = ConsoleColor.Blue;
Console.WriteLine("======================");
Console.ForegroundColor = ConsoleColor.Red;
Console.WriteLine("请选择你想吃的菜:选择菜编号点餐,输入0退出");
while (true)
{
int index =int.Parse(Console.ReadLine());
switch (index)
{
case 1:
Console.WriteLine("您选择的是:土豆丝 12元");
count += 12;
break;
case 2:
Console.WriteLine("您选择的是:拍黄瓜 10元");
count += 10;
break;
case 3:
Console.WriteLine("您选择的是:红烧肉 28元");
count += 28;
break;
case 4:
Console.WriteLine("您选择的是:水煮肉 30元");
count += 30;
break;
case 0:
Console.WriteLine("本次共消费{0}元",count);
break;
default:
break;
}
}
}