Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
csharp basic exercises: Get Planet Name By ID [Difficulty: 0]:
This function returns an incorrect value. Can you figure out why?
getPlanetName(3); //应该返回"地球"
get_planet_name(3)# 应该返回 '地球'
get_planet_name(3)# 应该返回 '地球'
getPlanetName(3)# 应该返回 '地球'
Programming objectives:
public class Kata
{
public static string GetPlanetName(int id)
{
string name;
switch(id)
{
case 1:
name = "Mercury";
case 2:
name = "Venus";
case 3:
name = "Earth";
case 4:
name = "Mars";
name = "Jupiter";
case 6:
name = "Saturn";
case 7:
name = "Uranus";
case 8:
name = "Neptune";
Test sample:
namespace Solution {
using NUnit.Framework;
using System;
[TestFixture]
public class SolutionTest
{
[Test]
public void Test()
Assert.AreEqual("Jupiter", Kata.GetPlanetName(5));
}
}
}
Best answer (multiple solutions):
More related topics:
Disclaimer
This blog All programming topics and answers were collected from the Internet, users are mainly used for study and reference, if any violation of your rights, please contact the administrator to delete, thank
entitled to collect https://www.codewars.com/
HTTPS: / /www.codewars.com/kata/get-planet-name-by-id