更新时间:2023-02-14 22:39:36
这是一种方式:静态 void Main( string [] args)
{
Console.WriteLine( 1);
Console.WriteLine( 2);
Console.WriteLine( 10);
Console.WriteLine( 9);
Console.WriteLine( 3);
Console.WriteLine( 4);
Console.WriteLine( 8);
Console.WriteLine( 7);
Console.WriteLine( 5);
Console.WriteLine( 6);
Console.ReadLine();
}
这是另一个:static void Main()
{
int [] data = new int [] { 1 , 2 , 10 , 9 , 3 , 4 , 8 , 7 , 5 , 6 };
foreach ( int i in 数据)
{
Console.WriteLine( 我懒得写自己的代码:{0},i);
}
Console.ReadLine();
}
使用此解决方案
设计:< html xmlns = http://www.w3.org/1999/xhtml\" >
< head runat = server >
< title > Untitled Page < / title & gt;
< / head >
< body >
< 表单 id = form1 runat = server >
< div >
< asp:TextBox ID = TextBox1 runat = server > < / asp:TextBox >
< br / >
< br / >
< asp:按钮 ID = Button1 runat = server OnClick = Button1_Click 文本 = 按钮 / > < / div >
< / form >
< / body >
< / html >
------------------------------ ------
代码:
< pre lang = xml > protected void Button1_Click(object sender,EventArgs e)
{
int n = 0;
n = Convert.ToInt32(TextBox1.Text);
int j = 0;
for(int i = 1; i & lt; (n / 2)+1; i ++)
{
if(i%2 == 1)
{
Response.Write((n - (n - i))+& quot;& lt; / br& gt;& QUOT);
Response.Write((n - (n - (i + 1)))+& quot;& lt; / br& gt;& quot;);
}
else
{
Response.Write((n - j)+& quot;& lt; / br& gt;& quot; );
Response.Write((n - (j + 1))+& quot;& lt; / br& gt;& quot;);
j + = 2;
}
}
} < / pre > 跨度>
output
1
2
10
9
3
4
8
7
5
6
Here is one way:static void Main(string[] args) { Console.WriteLine("1"); Console.WriteLine("2"); Console.WriteLine("10"); Console.WriteLine("9"); Console.WriteLine("3"); Console.WriteLine("4"); Console.WriteLine("8"); Console.WriteLine("7"); Console.WriteLine("5"); Console.WriteLine("6"); Console.ReadLine(); }
Here is another:static void Main() { int[] data = new int[] { 1, 2, 10, 9, 3, 4, 8, 7, 5, 6 }; foreach (int i in data) { Console.WriteLine("I'm too lazy to write my own code: {0}", i); } Console.ReadLine(); }
Use this solution
Design:<html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>Untitled Page</title> </head> <body> <form id="form1" runat="server"> <div> <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> <br /> <br /> <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /></div> </form> </body> </html> ------------------------------------ Code: <pre lang="xml">protected void Button1_Click(object sender, EventArgs e) { int n = 0; n = Convert.ToInt32(TextBox1.Text); int j = 0; for (int i = 1; i < (n/2)+1; i++) { if (i % 2 == 1) { Response.Write((n - (n - i))+"</br>"); Response.Write((n - (n - (i + 1))) + "</br>"); } else { Response.Write((n - j) + "</br>"); Response.Write((n - (j + 1)) + "</br>"); j+=2; } } }</pre>