for (int y = 1; y <= 1; y++)
{
for (int f = 1; f<= 1; f++)
{
Console.Write(f);
}
Console.WriteLine();//换行
for (int e = 1; e<= 2; e++)
{
Console.Write(e);
}
Console.WriteLine();//换行
for (int d = 1; d<= 3; d++)
{
Console.Write(d);
}
Console.WriteLine();//换行
for (int c = 1; c <= 4; c++)
{
Console.Write(c);
}
Console.WriteLine();//换行
for (int b = 1; b <= 5; b++)
{
Console.Write(b);
}
Console.WriteLine();//换行
for (int a = 1; a <= 6; a++)
{
Console.Write(a);
}
Console.WriteLine();//换行
for (int x = 1; x <= 7; x++)
{
Console.Write(x);
}
Console.WriteLine();//换行
}
for (int x = 1; x <= 7; x++)
{
if(x>y)
{continue;}
Console.Write(x);
}
改一个变量就行,只需要一个字母哦。
在最里面的循环加上这个条件就行if(x>y){ break;}就行!?
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
class Program
{
static void Main(string[] args)
{
for (int y = 1; y <= 7; y++)
{
for (int x = 1; x <= y; x++)
{
Console.Write(x);
}
Console.WriteLine();//换行
}
}
}
}
static void Main(string[] args)
{
for (int y = 1; y <= 7; y++)
{
for (int x = 1; x <= 7; x++)
{
if(x>y){
break;
}
Console.Write(x);
}
Console.WriteLine();//换行
}
}
for (int y = 1; y <= 7; y++)
{
for (int x = 1; x <= y; x++)
{
Console.Write(x);
}
Console.WriteLine();//换行
}
static void Main(string[] args)
{
for (int y = 1; y <= 7; y++)
{
for (int x = 1; x <= y; x++)
{
Console.Write(x);
}
Console.WriteLine();//换行
}
}
if (x == y)
namespace Test
{
class Program
{
static void Main(string[] args)
{
for (int y = 1; y <= 7; y++)
{
for (int x = 1; x <= y; x++)
{
Console.Write(x);
}
Console.WriteLine();//换行
}
}
}
}
for (int y = 1; y <= 7; y++)
{
for (int x = 1; x <= y; x++)
{
Console.Write(x);
}
Console.WriteLine();//换行
}
应该是if(x=y)和(x>=y)可以。x<=y的话,每行就只能输出一个数
for (int y = 1; y <= 7; y++)
{
for (int x = 1; x <= 7; x++)
{
if (x<=y) {
Console.Write(x);
}
}
Console.WriteLine();//换行
}
x<=y,即可!
x=y即可