用c#调用两个类随意输入三个数比较大小按顺序输出的代码

2024-12-29 15:47:28
推荐回答(4个)
回答1:

楼上的循环不行啊~你试试输入3,2,1~起码双循环的~~~我这个是从小到大输出

using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int[] a = new int[3];
for (int i = 0; i < a.Length; i++)
a[i] = Int32.Parse(Console.ReadLine());
Array.Sort(a);
foreach (int t in a)
Console.Write(t + " ");
}
}
}

回答2:

我这个随便输入几数的,从小到大排.
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication29
{
class Program
{
static void Main(string[] args)
{
Console.Write("输入数:");
string[] s = Console.ReadLine().Split();
int len = s.Length;
int[] Int = new int[len];
for (int i = 0; i < s.Length; i++)
{
Int[i] = Convert.ToInt32(s[i]);
}
Array.Sort(Int);
foreach (int t in Int)
{
Console.Write(t + " ");
}
Console.ReadLine();
}
}
}

回答3:

static void Main(string[] args)
{
int[] a = new int[3];
for (int i = 0; i < a.Length; i++)
a[i] = Int32.Parse(Console.ReadLine());
for (int i = 0; i < a.Length - 1; i++)
{
if (a[i] < a[i + 1])
{
int temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
}
}
foreach (int t in a)
Console.Write(t + " ");
}
从大到小输出
话说你说的调用两个类是什么意思?

回答4: