用c#程序编写:创建一个字符串数组,数组元素由键盘输入,输出那些含c的字符串

2025-01-18 18:17:07
推荐回答(2个)
回答1:

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

namespace TTest
{
class Sjx
{

static void Main(string[] args)
{

string []s=new string[5];
Console.WriteLine("输入5个字符串数组");
for (int i = 0; i < s.Length; i++)
{
s[i] = Console.ReadLine();
}
Console.WriteLine("////////////////////");
for (int i = 0; i < s.Length; i++)
{
for (int j = 0; j < s[i].Length; j++)
{
if (s[i][j].Equals('c'))
{
Console.WriteLine(s[i]);
break;
}
}
}
Console.ReadKey();
}
}
}

回答2:

public class CompareTest
{ static void Main()
{
string[] s = new string[5];
for (int i = 0; i < s.Length; i++)
{
s[i] = Console.ReadLine();
} //检查是否包含“s“:
Console.WriteLine("输出结果:");
foreach (var item in s)
{
if (item.IndexOf('c') >= 0 || item.IndexOf('C')>=0)
{
Console.WriteLine(item);
}
}
}}