小编VaV*_*aVa的帖子

创建哈希的快捷方式

我是Ruby的新手.我正在阅读关于Rubymonk的教程,我正在学习如何创建哈希.你能告诉我为什么我不能在没有key_value_pairs变量的情况下创建哈希.我的代码抗性大脑似乎合乎逻辑,代码应该在没有它的情况下工作,但事实并非如此.

这不起作用

def artax
  a = [:punch, 0]
  b = [:kick, 72]
  c = [:stops_bullets_with_hands, false]

  Hash[a,b,c]
end
p artax
Run Code Online (Sandbox Code Playgroud)

这有效.

def artax
  a = [:punch, 0]
  b = [:kick, 72]
  c = [:stops_bullets_with_hands, false]
  key_value_pairs = [a, b, c]
  Hash[key_value_pairs]
end
p artax
Run Code Online (Sandbox Code Playgroud)

ruby hash keyvaluepair

6
推荐指数
1
解决办法
517
查看次数

(char)int从哪里得到它的符号?

作为一名计算机编程新手,我获得了涉及使用扑克牌套装符号的家庭作业.在我的研究过程中,我遇到了一种简单的方法来检索符号:

 Console.Write((char)6);
Run Code Online (Sandbox Code Playgroud)

给你♠

  Console.Write((char)3);
Run Code Online (Sandbox Code Playgroud)

给你♥

等等...

但是,我仍然不明白C#用于检索这些符号的逻辑.我的意思是,Unicode表中的♠符号是U + 2660,但我没有使用它.ASCII表甚至不包含这些符号.

所以我的问题是,背后的逻辑是什么(char)int

c# char

6
推荐指数
1
解决办法
123
查看次数

为什么我不能用Javascript innerHTML属性更新HTML列表项?

我正在尝试学习Javascript并决定自己尝试这个innerHTML属性.但浏览器似乎忽略了Javascript代码.我究竟做错了什么?

 <!DOCTYPE html>
    <html>
      <head>
        <title>JavaScript - Document Object Model </title>

        <meta name="viewport" content="width=device-width, initial-scale=1.0">
      </head>
      <body>
        <div id="page">
          <h1 id="header">List</h1>
          <h2>Buy groceries</h2>
          <ul id="todo">
            <li id="one" class="hot"><em>fresh</em> figs</li>
            <li id="two" class="hot">pine nuts</li><li id="three" class="hot">honey</li>
            <li id="four">balsamic vinegar</li>
         </ul>
       </div>

     <script type="text/javascript">
       var thirdItem = getElementById('three');
       var itemContent = thirdItem.innerHTML;
       thirdItem.innerHTML = '<li id="three" class="hot">chicken</li>';
     </script>
   </body>
  </html>
Run Code Online (Sandbox Code Playgroud)

html javascript html-lists

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

难以将字符串解析为DateTime

以下代码给出了以下错误:

"未处理的异常:字符串未被识别为有效的DateTime.

从索引0开始有一个未知单词."

如何在此处将字符串正确转换为DateTime?

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

namespace Exercise
{
    class Program
    {
        static void Main(string[] args)
        {  
            Console.Write("Enter your birthday in format(dd.mm.yyyy): ");
            DateTime userBirthday = DateTime.Parse(Console.ReadLine());
            long result = DateTime.Today.Subtract(userBirthday).Ticks;
            Console.WriteLine("You are {0} years old.", new DateTime(result).Year - 1);
            Console.WriteLine("After 10 years you will be {0} years old.", new DateTime(result).AddYears(10).Year - 1);
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

c# datetime

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

浏览器会忽略Javascript

菜鸟提醒!你能告诉我为什么我的Javascript代码不会更新消息.浏览器运行HTML但忽略了Javascript代码.我究竟做错了什么?

<!DOCTYPE html>

<html>
<head>
  <title>Basic Function </title>

  <script type="text/javascript">


var msg = 'Sign up to receive our newsletter for 10% off!';

function updateMessage() {
  var el = document.getElementById('message');
  el.textContent = msg;
}

updateMessage();
  </script>
</head>
<body>
<h1> Travel Worthy </h1>
<div id="message">Welcome to our site! </div>  
  </body>
</html>
Run Code Online (Sandbox Code Playgroud)

html javascript

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

使用©符号绘制三角形

看看这个问题:编写一个打印9个版权符号三角形的程序©

控制台应使用这些©符号打印一个简单的三角形.三角形必须是空的,没有充满©东西.

我更改了控制台字符编码:

 Console.OutputEncoding = Encoding.UTF8;
Run Code Online (Sandbox Code Playgroud)

所以©打印正确.我也改变了字体.

我一直试图通过使用for循环来找出绘制三角形的方法,但我的新手知识显然仍然不足以完成这类任务.

你能给我一些关于如何用for循环绘制三角形的提示/提示吗?

顺便说一句,我发现问题解决了这样:

Console.OutputEncoding = Encoding.UTF8;
        char copyRight = '\u00A9';
        Console.WriteLine("{0,4}\n{0,3}{0,2}\n{0,2}{0,4}\n{0}{0,2}{0,2}{0,2}", copyRight);
Run Code Online (Sandbox Code Playgroud)

c# for-loop

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

仅返回上一次迭代的值

我试图用a来计算最大公约数while loop.因此,我正在寻找最大的数字(即循环的最后一个值).我如何摆脱前面的数字?

示例:84和18的最大公约数是6.但是,我的代码给出了数字2,3和6.如果只获取最后一个数字,我需要更改什么?

using System;

namespace CalculateGCD
{
    class Program
    {
        static void Main(string[] args)
        {

            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());


            int i = 1;

          while (i <= Math.Min(a, b))
            {             
                i++;

                if (a % i == 0 && b % i == 0)
                {
                    Console.WriteLine("GCD:{0}", i);
                }             
            }

        }

    }
}
Run Code Online (Sandbox Code Playgroud)

c# loops

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

标签 统计

c# ×4

html ×2

javascript ×2

char ×1

datetime ×1

for-loop ×1

hash ×1

html-lists ×1

keyvaluepair ×1

loops ×1

ruby ×1