帮我基本调试 [英] Help me basic debug

查看:64
本文介绍了帮我基本调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点问题。我不知道该如何回答?



这里样本输出:



a + b = 3

c的价值是:5



请帮帮我谢谢



我尝试过:



int a = 1;

double b = 2;

int c;



Console.WriteLine(a + b =+(a + b));

Console.WriteLine(c的值为:+ c);

I have a problem a bit. I don't know how should I put answer?

Here sample output:

a + b = 3
The value of c is: 5

please help me thanks

What I have tried:

int a = 1;
double b = 2;
int c;

Console.WriteLine("a + b = " + (a + b));
Console.WriteLine("The value of c is: " + c);

推荐答案

在发布的代码中,您永远不会分配 c ,因此这些代码甚至不应该编译。如果你试图在 c 中存储计算结果,那么就这样做:

c =(int)( a + b);

顺便问一下:为什么要将整数值与浮点数混合?
In the posted code, you never assign c, hence such code shouldn't even compile. If you are trying to store in c the result of the computation then do it:
c = (int) (a+b);
By the way: why are you mixing integer values with floating point ones?


麻烦的是你没有分配任何东西。

想象一个变量作为你衬衫的口袋,它可以容纳一件物品:一支笔,一支铅笔,一个手绢。

除非你明确地把东西放在口袋里,你不能把它拿出来!

所以尝试做手术,但把结果放到口袋里:

The trouble is that you aren't assigning anything.
Think of a variable as a pocket in your shirt, which can hold an item : a pen, a pencil, a hankie.
Unless you explicitly put something in the pocket, you can't take it out!
So try doing the operation, but putting the result into the "pocket":
int a = 1;
int b = 2;
int c = a + b;
Console.WriteLine("The value of {0} + {1} is {2}", a, b, c);

你不应该混合类型,除非你需要 - 它可能会导致一些奇怪的问题 - 所以我改变了 b的声明 double int 以匹配 a c

最后一行只是一个整齐的形式或你所拥有的:字符串中的花括号将使用数字作为计数替换为其后的列表中的值:{0}将替换为第一个值(在本例中为变量 a ) ,{1}将替换为第二个值(在这种情况下来自变量 b ),依此类推。

试一试,看看会发生什么!

You shouldn't "mix types" unless you need to - it can cause some odd problems - so I changed the declaration of b from double to int to match a and c.
The final line is just a "tidy up" form or what you had: the curly brackets in the string will be replaced with the value from the list after it, using the number as a count: {0} will be replaced with the first value (in this case from the variable a), {1} will be replaced with the second value (in this case from the variable b), and so on.
Try it and see what happens!


这篇关于帮我基本调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆