为什么将某个东西声明为双精度数据类型会使IDE误以为它是整数?

huangapple go评论84阅读模式
英文:

How come declaring something as a double data type would lead the ide to think it is a integer?

问题

抱歉,我不能直接处理图片内容。如果您可以将您要翻译的文本以文字形式提供给我,我将能够帮助您翻译它。

英文:

I am very confused on how a declared double data type would lead to the intellij ide to believe I was requiring a int to declare. Can someone give me some insight on this?

Here is the code in a picture:
enter image description here

答案1

得分: 0

方括号内的值用于定义数组的长度,因此需要一个整数。
如果您希望 cholo 放入数组中,则使用

double[] yu = new double[] {cholo};
英文:

The value inside the square brackets is for defining the length of the array, therefore it needs an int.
If you want cholo to be in the array then use

double[] yu = new double[] {cholo};

答案2

得分: 0

你已经传递了整数类型的双精度数组大小,这就是你遇到该错误的原因。以下是创建并初始化双精度数组的快捷语法:

double[] values = {1, 2, 3, 4};
英文:

You have pass the size of the double array which is integer, that's why you're getting that error.
This is the shortcut syntax to create and initialize an array of double

double[] values = {1,2,3,4,};

答案3

得分: 0

Double数据类型:

双精度数据类型是一种双精度的64位IEEE 754浮点数。其值范围是无限的。双精度数据类型通常用于十进制值,就像float一样。双精度数据类型也不应用于精确值,比如货币。其默认值是0.0d。

示例:double d1 = 12.3

Double[] yu = new Double[cholo]

您试图声明一个大小为double的数组,它可以是浮点数,所以您应该在[]中声明一个整数,因为它表示您要存储的double类型的元素数量。

英文:

Double Data type :

The double data type is a double-precision 64-bit IEEE 754 floating point. Its value range is unlimited. The double data type is generally used for decimal values just like float. The double data type also should never be used for precise values, such as currency. Its default value is 0.0d.

Example: double d1 = 12.3

Double[] yu=new Double[cholo]

you are trying to declare an array of size double which can be floating, so you should declare an integer in the [], As it indicates the number of the element you want to store of type double.

huangapple
  • 本文由 发表于 2020年5月29日 09:38:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/62077279.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定