小编use*_*842的帖子

如何在控制台窗口中将字符串设为粗体?

所以我试图找到一个简单的代码,使我的代码以粗体打印。当我在互联网上搜索时,所有这些都非常复杂,甚至不值得。有没有更简单的方法来制作字符串或只是一个 Console.WriteLine(" "); 胆大?

Console.Write("Type in the number of people to create: ");
int time = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("\nGenerating " + time + " people please stand by...");
System.Threading.Thread.Sleep(3000);
Console.Clear();
Run Code Online (Sandbox Code Playgroud)

c#

4
推荐指数
1
解决办法
2161
查看次数

有没有办法修改这个循环?

所以我试图让这个代码测试用户输入的单词中是否有某些字母,并确定该用户输入中有多少该特定字母。

目前aCounterbCounter如果我输入这个词,我会得到 4 for和 4 for "aabb"

我如何做到这一点,例如,如果有 2 个 a 并且它已经测试了2 次,则测试字母的循环会"a"停止"a"

static int aCounter, bCounter;

public static void Main (string[] args)
{
    Console.Write("Enter the secret word: ");
    string word = Console.ReadLine();

    for(int i = 0; word.Length > i; i++)
    {       
        if (word.Count(letter => letter == 'a') > 0)
        {
            Console.WriteLine("\nThe word contains a");
            aCounter++;
        }

        if (word.Count(letter => letter == 'b') > 0)
        {
            Console.WriteLine("\nThe word …
Run Code Online (Sandbox Code Playgroud)

c#

3
推荐指数
1
解决办法
61
查看次数

标签 统计

c# ×2