3 回答

TA貢獻(xiàn)1796條經(jīng)驗(yàn) 獲得超10個(gè)贊
簡(jiǎn)單的寫了一個(gè)給數(shù)組賦值的方法,不知道是不是符合你的要求
int[] array = new int[10];//聲明一個(gè)int型的數(shù)組
for (int x = 0; x < array.Length; x++)//用于循環(huán)輸入
{
Console.WriteLine("請(qǐng)輸入數(shù)字:");
int number = int.Parse(Console.ReadLine());//鍵盤輸入一個(gè)數(shù)字
for (int i = 0; i < array.Length; i++)//循環(huán)向數(shù)組中添加元素
{
if (array[i] == 0)
{
array[i] = number;//給數(shù)組賦值
break;//跳出循環(huán)
}
}
}
for (int j = 0; j < array.Length; j++)//循環(huán)輸出數(shù)組
{
Console.WriteLine(string.Format("數(shù)組第{0}:{1}", j + 1, array[j]));
}
Console.ReadLine();

TA貢獻(xiàn)1828條經(jīng)驗(yàn) 獲得超6個(gè)贊
static void Main(string[] args)
{
Console.WriteLine("請(qǐng)輸入第一個(gè)數(shù):");
string str = Console.ReadLine();
Console.WriteLine("請(qǐng)輸入第二個(gè)數(shù):");
str += Console.ReadLine();
Console.WriteLine("請(qǐng)輸入第三個(gè)數(shù):");
str += Console.ReadLine();
StringBuilder s = new StringBuilder();
char[] c = str.ToCharArray();
Array.Reverse(c);
for (int i = 0; i < c.Length; i++)
{
s.Append(c[i]);
}
Console.WriteLine(s.ToString());
Console.ReadKey();
}
編譯通過(guò)
- 3 回答
- 0 關(guān)注
- 642 瀏覽
添加回答
舉報(bào)