问题描述
我是C#的新手,我正在测试我构建的应用程序,需要5个数字的值,用3个空格分隔。 没有必要为我的作业演示一个负整数,但我想知道为什么我不能使用负整数。 我是否需要额外的
语句来允许负整数? 我想我认为一个32位整数允许负数? Visual Studio将我重定向到语句
I am new to C# and I'm testing the app I built requiring a 5-digit value separated by 3 spaces. It is not necessary to demonstrate a negative integer for my assignment, but am wondering why I cannot use negative integers. Would I need an additional statement to allow negative integers? I guess I thought a 32-bit integer allows negative numbers? Visual Studio redirected me to the statement
int number =
Convert 。ToInt32( 控制台 .ReadLine());
提前感谢您阅读我的代码!
Thanks in advance for reading my code!
class Program
{
static void Main(string [] args)
{
Console.Write("输入5位数字:");
int number = Convert.ToInt32(Console.ReadLine());
  Console.WriteLine("您选择的号码是{0}。",数字);
$
  ;     int digit1,
digit2,&
digit3,
digit4,
digit5;
$
digit1 = number / 10000;
number = number%10000;
digit2 = number / 1000;
number = number%1000;
digit3 = number / 100;
number = number%100;
digit4 = number / 10;
number = number%10;
digit5 = number / 1;
number = number%1;
string space3 =" " ;;
Console.WriteLine(" {1} {0} {2} {0} {3} {0} {4} {0} {5}",space3,digit1,digit2,digit3,digit4,digit5);
Console.ReadLine();
}
}¥b $ b}
class Program
{
static void Main(string[] args)
{
Console.Write("Enter a 5 Digit Number: ");
int number = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("The Number You Chose is {0}.", number);
int digit1,
digit2,
digit3,
digit4,
digit5;
digit1 = number / 10000;
number = number % 10000;
digit2 = number / 1000;
number = number % 1000;
digit3 = number / 100;
number = number % 100;
digit4 = number / 10;
number = number % 10;
digit5 = number / 1;
number = number % 1;
string space3 = " ";
Console.WriteLine("{1}{0}{2}{0}{3}{0}{4}{0}{5}", space3, digit1, digit2, digit3, digit4, digit5);
Console.ReadLine();
}
}
}
推荐答案
这篇关于Visual Studio 2017 C#ToInt32方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!