我發了一個號碼,要求用C#輸入2個數字,並以相應的消息作爲響應。第二個數字如何起作用? 無論我爲第二個數字輸入什麼,我都會收到消息「您的號碼在0-10範圍內」。C#控制流程
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string myInput; // declaring the type of the variables
int myInt;
string number1;
int number;
Console.WriteLine("enter a number");
myInput = Console.ReadLine(); //muyInput is a string which is entry input
myInt = Int32.Parse(myInput); // myInt converts the string into an Integer
if (myInt > 0)
Console.WriteLine("Your number {0} is greater than zero.", myInt);
else if (myInt < 0)
Console.WriteLine("Your number {0} is less than zero.", myInt);
else
Console.WriteLine("Your number {0} is equal zero.", myInt);
Console.WriteLine("enter another number");
number1 = Console.ReadLine();
number = Int32.Parse(myInput);
if (number < 0 || number == 0)
Console.WriteLine("Your number {0} is less than zero or equal zero.", number);
else if (number > 0 && number <= 10)
Console.WriteLine("Your number {0} is in the range from 0 to 10.", number);
else
Console.WriteLine("Your number {0} is greater than 10.", number);
Console.WriteLine("enter another number");
}
}
}
確實有人說「weltgeist」? ;) – 2011-01-06 21:41:36