【发布时间】:2016-12-19 00:03:13
【问题描述】:
最近我试图解决hackerrank 30天代码挑战的第1天数据类型课程,我遇到了一个奇怪的路障。编译器一直说我的输出是错误的答案,但我打印出来完全相同的整数双精度和字符串。 唯一不同的是我的双精度没有小数点,这没有意义,因为我所做的唯一一件事就是从输入中读取,将输入从字符串转换为double 然后将两个 double 相加
你们能帮忙吗?顺便说一下,这是我的 C# 代码。
using System;
using System.Collections.Generic;
using System.IO;
class Solution {
static void Main(String[] args) {
int i = 4;
double d = 4.0;
string s = "HackerRank ";
//this is the start of my code,the top part is preset by hackerrank
int a=Convert.ToInt32(Console.ReadLine());
double x = Convert.ToDouble(Console.ReadLine());
string l = Console.ReadLine();
Console.WriteLine(a+i);
Console.WriteLine(d+x);
Console.WriteLine(s+l);
Console.ReadLine();
}
}
这里有他们希望我使用的输入:
12
4.0
is the best place to learn and practice coding!
这是我的输出:
16
8
HackerRank is the best place to learn and practice coding!
以及他们想要的输出:
16
8.0
HackerRank is the best place to learn and practice coding!
您可以看到我的替身缺少“.0”,有什么帮助吗?
【问题讨论】: