小编jos*_*hew的帖子

是否有特定的方法让用户使用“#”等分隔符输入值?

我有下面的代码,它应该要求用户输入由#(如1#2#3##2等)分隔的各种整数。然后应该找到输入序列中具有重复的值并将其显示为“序列包含 2 个重复值”。

但是,我不确定用于分隔用户输入值的代码是否正确,因为它显示错误:

错误的图像

public class Program
{
    public static void Main(string[] args)
    {  
        // Keep the following line intact 
        Console.WriteLine("===========================");

        // Insert your solution here.     
               
        // user input gets the input from the user 
       
        // regarding a line where integers are separated by # 
       
        String userInput;

        Console.WriteLine("Please enter single line containing a list of integers, separated by '#':");

        userInput = Console.ReadLine();

        // splitting the userInput into Array of Strings  
        if (userInput != null)
        {
            // …
Run Code Online (Sandbox Code Playgroud)

c#

0
推荐指数
1
解决办法
114
查看次数

标签 统计

c# ×1