小编Boa*_*ann的帖子

地板功能对于正数和负数不对称

我使用的是Python 3.4.3.该math.floor功能为我提供了正面和负面数字的不同答案.例如:

>>> math.floor (19.8)
19

>>> math.floor (-19.8)
-20
Run Code Online (Sandbox Code Playgroud)

为什么我在答案中得到了这个差异?

python math floor

-7
推荐指数
1
解决办法
5425
查看次数

当我为同一对象重用不同的哈希码时,为什么HashMap会覆盖现有对象?

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)

java java-8

-7
推荐指数
1
解决办法
101
查看次数

为什么“extern”关键字在同一个文件中不起作用?

请参阅下面的示例代码以了解“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)

c++ conditional-operator extern

-8
推荐指数
1
解决办法
128
查看次数

这两个程序有什么区别?

这两个程序有什么区别?对于第一个程序,我的输出为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)

c++

-9
推荐指数
1
解决办法
107
查看次数

有人可以解释为什么编译吗?

我是Python的新手,正在尝试并运行了以下代码:

a=13
a==14
print(a)
Run Code Online (Sandbox Code Playgroud)

我希望该程序不会由于第二行而编译,尽管令人惊讶的是它可以编译(尽管我看不到它所做的任何更改)。有人可以解释为什么吗?如果我使用a===14而不是a==14错误。

python variable-assignment assignment-operator python-3.x

-9
推荐指数
1
解决办法
82
查看次数

为什么输出"geeksforgeeks"?

#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 "只期待.

c++

-10
推荐指数
1
解决办法
159
查看次数

为什么-1在C++中变成-842150451?

struct myclass {
    int id;
    myclass(): id(-1){};
};

myclass *a;
cout >> a->id;
Run Code Online (Sandbox Code Playgroud)

以上是我的长程序的演示.输出应为-1.但我不知道为什么输出变成-842150451.

c++

-10
推荐指数
1
解决办法
379
查看次数

如何在 JavaScript 中获取数字的阶乘?

我正在学习 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)

javascript factorial

-11
推荐指数
1
解决办法
2646
查看次数

下划线在Java数字中不可见

下划线在整数数据类型中不可见:

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)

java

-14
推荐指数
1
解决办法
88
查看次数