控制台中的错误是什么? [英] What is the error in Console?
本文介绍了控制台中的错误是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
static void Main(string[] args)
{
int n, m, c, a;
n = Convert.ToInt32(Console.WriteLine());
a = n;
{
m = n % 10;
a = n % 10;
}
while(n != 0)
{
c--;
m = n % 10;
n = n / 10;
a = a + m * Math.Pow(10,c);
Console.ReadKey();
}
}
推荐答案
您正在使用Console.WriteLine
用于将输出写入控制台。你想要Console.ReadLine
,用于从控制台读取输入。
You are usingConsole.WriteLine
which is for writing output to the console. You wantConsole.ReadLine
, for reading input from the console.
n = Convert.ToInt32(Console.ReadLine());
哦,
真是个错误!
和此错误:
oh ,
What a mistake !
and this Error :
a = a + m * Math.Pow(10,c);
你得到的错误是
引用:
不能隐含地将类型'double'转换为'int'。存在显式转换(您是否错过了转换?)
Cannot implicitly convert type 'double' to 'int'. An explicit conversion exists (are you missing a cast?)
因为 math.Pow()返回 double ,并且您正尝试将结果直接分配到 int
尝试使用
because math.Pow() returns a double and you are trying to directly assign the results into an int
Try using
double a;
您还尝试使用未初始化的变量 c - 尝试
int n, m, c = 0;
这篇关于控制台中的错误是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文