我使用的是Python 3.4.3.该math.floor功能为我提供了正面和负面数字的不同答案.例如:
>>> math.floor (19.8)
19
>>> math.floor (-19.8)
-20
Run Code Online (Sandbox Code Playgroud)
为什么我在答案中得到了这个差异?
import java.util.HashMap;
import java.util.Map;
class Geek
{
public String name;
public int id;
Geek(String name, int id)
{
this.name = name;
this.id = id;
}
@Override
public boolean equals(Object obj)
{
// checking if both the object references are
// referring to the same object.
if(this == obj)
return true;
// it checks if the argument is of the
// type Geek by comparing the classes
// of the passed argument and this object.
// if(!(obj instanceof Geek)) return false; …Run Code Online (Sandbox Code Playgroud) 请参阅下面的示例代码以了解“extern”的使用。当我在代码中使用 extern 关键字时,出现编译错误。请提出问题的解决方案。
#include<iostream>
extern int x;
extern int y;
extern int z;
int main(){
x = 10;
y = 15;
z = (x>y ? x: y);
std::cout<<z;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
错误信息:
example8.cpp:(.rdata$.refptr.z[.refptr.z]+0x0): undefined reference to `z';
example8.cpp:(.rdata$.refptr.y[.refptr.y]+0x0): undefined reference to `y';
example8.cpp:(.rdata$.refptr.x[.refptr.x]+0x0): undefined reference to `x';
F:\DEVC_workspace\collect2.exe [Error] ld returned 1 exit status
Run Code Online (Sandbox Code Playgroud) 这两个程序有什么区别?对于第一个程序,我的输出为9,对于第二个程序,我的输出为10。
#include <iostream>
using namespace std; // So we can see cout and endl
int main()
{
int x = 0; // Don't forget to declare variables
while ( x < 10 ) { // While x is less than 10
cout << x << endl;
x++; // Update x so the condition can be met eventually
}
cin.get();
}
Run Code Online (Sandbox Code Playgroud)
#include <iostream>
using namespace std; // So we can see cout and endl
int main()
{
int x = 0; …Run Code Online (Sandbox Code Playgroud) 我是Python的新手,正在尝试并运行了以下代码:
a=13
a==14
print(a)
Run Code Online (Sandbox Code Playgroud)
我希望该程序不会由于第二行而编译,尽管令人惊讶的是它可以编译(尽管我看不到它所做的任何更改)。有人可以解释为什么吗?如果我使用a===14而不是a==14错误。
#include <iostream>
using namespace std;
int main()
{
if (!(cout << "geeks"))
cout <<" geeks ";
else
cout << "forgeeks ";
return 0;
}
Run Code Online (Sandbox Code Playgroud)
为什么cout << "geeks";在if条件中执行?我知道if语句是假的.我"forgeeks "只期待.
struct myclass {
int id;
myclass(): id(-1){};
};
myclass *a;
cout >> a->id;
Run Code Online (Sandbox Code Playgroud)
以上是我的长程序的演示.输出应为-1.但我不知道为什么输出变成-842150451.
我正在学习 Java 脚本,有一个关于获取用户输入的数字的阶乘的练习,但由于某种原因我总是得到答案是 = 1
这是我的代码:
<SCRIPT>
function factorial(num){
for (n=1; n<=num; n++){
return fact*n;
}
}
var myNum, fact;
myNum = parseFloat(window.prompt('Enter positive integer : ',''));
fact = 1;
document.write('the factorial of the number is = '+ factorial(myNum));
</SCRIPT>
Run Code Online (Sandbox Code Playgroud) 下划线在整数数据类型中不可见:
int intHex = 0x0041;
System.out.println("intHex: " + intHex);
int intBinary = 0b01000001;
System.out.println("intBinary: " + intBinary);
int intUnderscore = 1_23_456;
System.out.println("intUnderscore: " + intUnderscore);
Run Code Online (Sandbox Code Playgroud) c++ ×4
java ×2
python ×2
extern ×1
factorial ×1
floor ×1
java-8 ×1
javascript ×1
math ×1
python-3.x ×1