标签: integer

如何在数组中查找非字符串索引

有一个像

a = ['string', '1', '2', 'string2', '4', 'string5', '5' ...]
Run Code Online (Sandbox Code Playgroud)

我怎样才能找到像这样的非字符串索引

[1,2,4,6 ...]
Run Code Online (Sandbox Code Playgroud)

它不起作用如果我使用

isinstance(a, str)
Run Code Online (Sandbox Code Playgroud)

python string integer indices python-3.x

0
推荐指数
1
解决办法
94
查看次数

测试高数在 C 中是奇数还是偶数

我试图测试一个数字是偶数还是奇数。

它适用于 8 位数字,但当我超过 9 位数字时,它看起来很奇怪。我输入的数字发生了变化。

8位数字示例:

Enter the ID : 20202020
20202020 is even.
Program ended with exit code: 0
Run Code Online (Sandbox Code Playgroud)

但是当用 10 位数字做它时,它看起来像这样:

Enter an integer: 2345678915
-1949288381 is odd.
Program ended with exit code: 0
// these nr that are different, what are they? 
//Have not found any info about it either... 
Run Code Online (Sandbox Code Playgroud)

代码:

#include <stdio.h>

int main() 
{ 

    int id;
    printf("Enter the Id: ");
    scanf("%d", &id);

    if(id % 2 == 0)
        printf("%d is even.\n", id);
    else
        printf("%d is …
Run Code Online (Sandbox Code Playgroud)

c integer if-statement

0
推荐指数
1
解决办法
87
查看次数

如何将一串数字转换为整数数组?

我有一个类似的字符串,"12345"并且想将它转换为整数数组{1,2,3,4,5}.

我想要一种将字符转换为整数的方法,'1' -> 1. 以及另一种创建数组的方法。

这是我到目前为止:

public static int charToInt(char character) {
    int newInt;

    newInt = (int) character;

    return newInt;
}

public static int[] convertStringToIntArray(String keyString) {
    int keyLength = keyString.length();
    int element;

    int[] intArray = new int[keyLength];

    for (element = 0; element < keyLength; element++) {
        intArray[element] = charToInt(keyString.charAt(element));
    }

    // return
    return intArray;
}
Run Code Online (Sandbox Code Playgroud)

我认为问题出在charToInt方法上。我认为它正在将 转换char为它的ascii值。但我不确定另一种方法是否正确。

任何帮助将不胜感激。

java arrays string integer char

0
推荐指数
1
解决办法
103
查看次数

VBA Excel 使用来自另一个模块的整数变量

我有

Dim PackageInnerHorizontalwidth As Single
Run Code Online (Sandbox Code Playgroud)

在“Public Sub PackageDimensionsCalculator()”中,这是一些计算的结果。现在我需要在模块“Function EvaluateFormatSketch() As Boolean”中使用结果值“PackageInnerHorizo​​ntalwidth”,并将该值返回为“0”,这不是所有计算后的实际结果值。我试着先做那个

Dim PackageInnerHorizontalwidth As Single
Run Code Online (Sandbox Code Playgroud)

全球和公开但没有成功。我知道在我的情况下这不是这样做的方法。

所以我的问题是:如何将“PackageInnerHorizo​​ntalwidth”作为模块“Function EvaluateFormatSketch() As Boolean”中的值?

现在我把它作为

Dim PackageInnerHorizontalwidth As Integer
Run Code Online (Sandbox Code Playgroud)

请有人帮我解决这个问题吗?

excel vba integer

0
推荐指数
1
解决办法
66
查看次数

为什么增加 long long 比增加 int 慢得多?

我最近很想知道 C++ 可以在一秒钟内大致处理多少整数增量。为了测试这一点,我编写了一个简短的驱动程序,如下所示:

#include <iostream>

using namespace std;

int main()
{
    int num = 0;
    while(++num) {
        if(num%100000000 == 0) { // prints num every 100 million iterations
            cout << num << endl;
        }
    }

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

当我在 g++ 7.5.0 下用优化 -O3 编译这段代码时,程序设法每秒增加大约 800,000,000 次。

但是当我将 a 的类型切换int到 a 时long long,我发现性能严重下降,每秒大约 100,000,000 次。

有人可以解释为什么会出现这种差异吗?

c++ integer

0
推荐指数
1
解决办法
67
查看次数

我不明白为什么在这个 Java 问题中变量 result 的值是非零的

我有这个问题:

您认为执行以下 Java 代码段后变量 result 的值是多少?

int i = 1234567890;

float f = i;

int result = i - (int)f;
Run Code Online (Sandbox Code Playgroud)

答案非零

请记住,我是 Java 的初学者,目前正在学习绝对的基础知识,坦率地说,我不明白为什么答案是非零的,以及每一行代码的实际含义是什么?

java double integer

0
推荐指数
1
解决办法
58
查看次数

整数记忆

当我写:
Integer i = 5;
Integer i = new Integer(5);
这两行相等吗?
在内存中,类型i将像这两行一样在堆中分配吗?如果是的话,这一切是如何在记忆中发生的?

java memory integer

0
推荐指数
1
解决办法
115
查看次数

Python只在txt文件中写入For语句的最后一位数字

我有2个文件:

text.txt

和:

main.py

在main.py,我有以下代码:

for i in range(1,4097):
    i = str(i)
    file = open("text.txt","w")
    file.write(i)
Run Code Online (Sandbox Code Playgroud)

正如你所看到的,我想从1生成所有号码- 4096,但是当我运行该脚本,它只是写4096在text.txt。

我如何在里面写数字 1 - 4096 text.txt?

(顺便说一句,我做i了一个字符串 ( str()) 因为它有我和错误说 Python 只能写字符串而不是 Intigers:

Traceback (most recent call last):
  File "d:\path\app.py", line 14, in <module>
    file.write(i)
TypeError: write() argument must be str, not int
Run Code Online (Sandbox Code Playgroud)

)

谢谢

-D一个n我e升

python string integer for-loop write

0
推荐指数
1
解决办法
49
查看次数

根据 C 标准,int 的大小是多少?

我知道现在几乎所有的编译器都使用 4 个字节来表示 int,但如果我没记错的话,情况并非总是如此。

我也知道在 Intel 架构上 int 的大小总是与 CPU 匹配。例如,在 8 位 CPU 上,int 是 8 位。

我的问题是,如果有的话,C 标准对 int 的大小有什么规定吗?

c integer

0
推荐指数
1
解决办法
67
查看次数

将一些元素转换为 int

在python中,我想将列表的一些字符串元素转换为int。

所以我有:

my_list = [“汽车”、“10”、“20”、“50”、“60”、“13”、“自行车”]

如何制作:

my_list = ["汽车", 10, 20, 50, 60, 13, "自行车"]

python integer list

0
推荐指数
1
解决办法
42
查看次数

标签 统计

integer ×10

java ×3

python ×3

string ×3

c ×2

arrays ×1

c++ ×1

char ×1

double ×1

excel ×1

for-loop ×1

if-statement ×1

indices ×1

list ×1

memory ×1

python-3.x ×1

vba ×1

write ×1