小编sun*_*wer的帖子

在数组中查找重复的整数并显示它们出现的次数

我正在编写一个代码,用于打印出数组中重复的整数及其出现次数.我不允许使用LINQ,只是一个简单的代码.我想我是如此接近但对如何获得正确的输出感到困惑:

class Program
{
    static void Main(string[] args)
    {              
        int[] array = { 10, 5, 10, 2, 2, 3, 4, 5, 5, 6, 7, 8, 9, 11, 12, 12 };
        int count = 1;
        for (int i = 0; i < array.Length; i++)
        {
            for (int j = i; j < array.Length - 1 ; j++)
            {

               if(array[j] == array[j+1])
                  count = count + 1;
            }
            Console.WriteLine("\t\n " + array[i] + "occurse" + count);
            Console.ReadKey();
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# arrays duplicates

20
推荐指数
4
解决办法
9万
查看次数

按 Enter 键时出错,C# 控制台

我的代码要求用户输入一个字母(转换stringchar),但是当按下Enter键作为输入时,代码崩溃了。

我没有设置任何条件来向用户发送错误消息,不要Enter在输入时按下键并只输入字母。

这是我正在努力的部分:

public static char GetLetter(string prompt)
{
    char result;

    Console.Write("\n\t" + prompt + ":  ");
    result = Convert.ToChar(Console.ReadLine());

    if(result == '!' || result == '@' || result == '#'  || result == '$' || result == '%'  )
    // we can keep going with all the unwanted characters and numbers 
    {
        Console.WriteLine("\n\t NO MATCH ! \n\t ,please try again using letters only , ");
        result = GetLetter(prompt);
        return result;
    } …
Run Code Online (Sandbox Code Playgroud)

c# error-handling enter key

5
推荐指数
1
解决办法
1504
查看次数

HTML5和CSS,内部css样式不适用

我正在使用内部css,每当用任何浏览器测试它时,样式从未应用于标签.我已经验证了我的代码并且它已经通过.我不知道我哪里出错了.如果有人可以通过浏览器查看此页面来帮助我吗?谢谢.

<!DOCTYPE HTML>

<html>
<head>
<meta charset="utf-8" />
<title>Extend Your Knowledge - 3-1</title>

<style type="text/css">
<!--

body {font-family:"Garamond,Arial,Verdana; font-size:12pt;}

h1,h2 {color:red ; 
       font-variant:small-caps;}

.align-right {float:right;
              margin-left:15px;
              margin-right:15px;}

.align-left {float:left;
             margin-left:15px;
             margin-right:15px; }
a            {text-decoration:underline;
             color:red;}
a:hover      {background:red;
              color:white;}
              -->
              </style>

</head>
<body>

<section>
<article>
     <a id="top"></a>
     <h1>Isabel's Desserts</h1>
<p>We offer a variety of wonderful desserts at our cafe such as <a href="#eggnog">eggnog mousse</a> as well as <a href="#custard">decorative custards</a>.</p>

<a id="eggnog"></a>
<h2>Eggnog Mousse</h2>
<img class="align-left" src="mousse.jpg" width="560" height="420" alt="First dessert" …
Run Code Online (Sandbox Code Playgroud)

html css html5

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

标签 统计

c# ×2

arrays ×1

css ×1

duplicates ×1

enter ×1

error-handling ×1

html ×1

html5 ×1

key ×1