java 无法取消引用_java错误:double无法解除引用(java error: double cannot be dereferenced)...

java错误:double无法解除引用(java error: double cannot be dereferenced)

好的,所以我需要生成1到100之间的7个随机数,并在屏幕上打印最大值。 但是,当我编译这段代码时:

public class ArrayofTemperatures

{

public static void main(String[] args)

{

double [] temp = new double [7];

int index;

double max;

double random = Math.random() * 100 + 1;

temp[0] = random.nextDouble();

max = temp[0];

for (index = 1; index < temp.length; index++)

{

temp[index] = random.nextDouble();

if (temp[index] > max)

max = temp[index];

}

System.out.println("The highest score is: " + max);

}

}

我收到这两个错误:

ArrayofTemperatures.java:12:错误:double无法解除引用temp [0] = random.nextDouble();

ArrayofTemperatures.java:16:错误:double无法解除引用temp [index] = random.nextDouble();

ok so i need to generate 7 random numbers between 1 and 100 and have the max be printed on the screen. however, when i compile this code:

public class ArrayofTemperatures

{

public static void main(String[] args)

{

double [] temp = new double [7];

int index;

double max;

double random = Math.random() * 100 + 1;

temp[0] = random.nextDouble();

max = temp[0];

for (index = 1; index < temp.length; index++)

{

temp[index] = random.nextDouble();

if (temp[index] > max)

max = temp[index];

}

System.out.println("The highest score is: " + max);

}

}

I get these two errors:

ArrayofTemperatures.java:12: error: double cannot be dereferenced temp[0] = random.nextDouble();

ArrayofTemperatures.java:16: error: double cannot be dereferenced temp[index] = random.nextDouble();

原文:https://stackoverflow.com/questions/33801248

2019-10-31 15:28

满意答案

你很困惑。

此语句生成一个double值:

double random = Math.random() * 100 + 1;

如果您想要随机生成器,请使用

Random random = new Random ();

然后random.nextDouble()将生成一个介于0.0和1.0之间的数字。

另一种方法是用Math.random()替换对random.nextDouble()的调用。

You got confused.

This statement produces a single double value :

double random = Math.random() * 100 + 1;

If you want a Random generator, use

Random random = new Random ();

Then random.nextDouble() would produce a number between 0.0 and 1.0.

The alternative is to replace the calls to random.nextDouble() with Math.random().

2015-11-19

相关问答

你很困惑。 此语句生成一个double值: double random = Math.random() * 100 + 1;

如果您想要随机生成器,请使用 Random random = new Random ();

然后random.nextDouble()将生成一个介于0.0和1.0之间的数字。 另一种方法是用Math.random()替换对random.nextDouble()的调用。 You got confused. This statement produces a single ...

Char.getNumericValue是一个静态方法,它将值作为参数。 所以你要: int b = Char.getNumericValue(cha);

您不能使用原始类型作为任何类型的方法调用的目标。 Char.getNumericValue is a static method which takes the value as an argument. So you want: int b = Char.getNumericValue(cha);

You can't use primit...

长度是属性,而不是方法。 它应该是这样的: currentWord.length-1

编辑:从您使用currentWord的方式来看,它似乎是一个int,而且ints没有长度。 这可能是你想要做的: currentWord-1

Length is a property, not a method. It should be like so: currentWord.length-1

Edit: from how you're using currentWord, it appears to ...

它为我提供了一些小修复。 int ch;

JOptionPane.showMessageDialog (null, "1=+ 2=- 3=x 4=/ Please Choose Operation"); // Shows what numbers will do what operation when input

ch = (int)JOptionPane.showInputDialog("Please Choose Operation").charAt(0); /...

num2.num2不是你在Java中对数字进行平方的方式。 这是: double num1 = Math.random();

double num2 = Math.random();

if (num1 < num2*num2) {

//do something

}

请参阅Java教程:赋值,算术和一元运算符 。 num2.num2 is not how you square a number in Java. This is: double num1 = Math.random();

d...

这个命令checkbox.getPaintFlags() | textState.intValue() 二进制操作数的checkbox.getPaintFlags() | textState.intValue()被解释为((int)checkbox).getPaintFlags() ,它是错误的原因。 但! 如果你对操作数的颠倒顺序正确解释。 它的工作原理! 当我发现这个功能时,我很想知道 This order checkbox.getPaintFlags() | textState.intVal...

你只需要在你的return语句中添加new int[]来编译它。 如果你刚开始使用大括号,它不知道你想要什么。 请注意,这将返回一个新的数组,而原始的arr将具有相同的值。 即 return new int[] {arr[0]+1,arr[1]+1,arr[2]+1,arr[3]+1};

You just need to add new int[] to your return statement to compile it. It doesn't know what you want if y...

你错过了一个大括号(你没有关闭你的if ),你的sum.doubleValue()是不正确的(因为sum已经是一个原始的“double”)。 public double calcAverageBill(java.util.List monthlyBill) {

double sum = 0;

if (!monthlyBill.isEmpty()) {

for (double month : monthlyBill) {

sum += month;

...

星号和方括号都降低了取消引用的级别。 实际上, myArr[i]相当于*(myArr+i) ,而*ptr_myIntergerClass相当于ptr_myIntergerClass[0] 。 因此,您的任务相当于任何一项 *(myArr+i) = *ptr_myIntergerClass;

要么 myArr[i] = ptr_myIntergerClass[0];

两者都是有效的,因为它们的两侧都有相同的类型(即MyIntergerClass ),左侧是可分配的(即左值 )。 The aste...

From Code 返回类型void public void withNumberOfRipples(int numberOfRipples) {

if (numberOfRipples > 4 || numberOfRipples < 1)

numberOfRipples = 4;

this.numberOfRipples = numberOfRipples;

}

所以你不能链接你的函数调用,你需要调用MapRipple实例上的每个函数,而不是在void 解决方...

相关文章

java的double类型要保留两位小数有四种方法,都是四舍五入,例: import java.mat

...

static double min(double... array)返回存在于数组的最小值

在namenode启动脚本%Hadoop_HOME%/bin/start-dfs.sh的时候发现dat

...

eclipse里报:An internal error occurred during: Buildi

...

启动android模拟器时.有时会报The connection to adb is down, an

...

在solr中 添加新的索引词语时,报如标题所示错误,指定是插入的字段没有在solr索引字段里 可以修改

...

解决方法安装Solr过程出现错误,报异常 org.apache.solr.common.SolrExc

...

在本地环境运行正常,放到服务器出现Caused by: java.lang.IllegalArgume

...

以下是代码: #include<iostream>using namespace std

...

在win8上安装VirtualBox-4.2.4-81684-Win.exe,提示Installati

...

最新问答

如果启用了复制处理程序,请确保将其置于其中一个安全角色之后。 我见过人们做的另一件事是在不同的端口上运行admin。 最好在需要auth的页面上使用SSL,这样你就不会发送明确的密码,因此管理和复制将发生在8443上,而常规查询将在8080上发生。 如果您要签署自己的证书,请查看此有用的SO页面: 如何在特定连接上使用不同的证书? I didn't know that /admin was the context for SOLR admin because /admin does not re

第一:在您的样本中,您有: 但是你在询问 //td[@class=‘CarMiniProfile-TableHeader’] (注意TableHeader中的大写'T')。 xpath区分大小写。 第二:通过查询// td [@ class ='CarMiniProfile-TableHeader'] / td,你暗示你在外部td中有一个'td'元素,而它们是兄弟姐妹。 有很多方法可以在这里获得制作和模型

这是你的答案: http://jsfiddle.net/gPsdk/40/ .preloader-container { position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; background: #FFFFFF; z-index: 5; opacity: 1; -webkit-transition: all 500ms ease-out;

问题是,在启用Outlook库引用的情况下, olMailItem是一个保留常量,我认为当您将Dim olMailItem as Outlook.MailItem ,这不是问题,但是尝试设置变量会导致问题。 以下是完整的解释: 您已将olMailItem声明为对象变量。 在赋值语句的右侧,在将其值设置为对象的实例之前,您将引用此Object 。 这基本上是一个递归错误,因为你有对象试图自己分配自己。 还有另一个潜在的错误,如果之前已经分配了olMailItem ,这个语句会引发另一个错误(可能是

我建议使用wireshark http://www.wireshark.org/通过记录(“捕获”)设备可以看到的网络流量副本来“监听”网络上发生的对话。 当您开始捕获时,数据量似乎过大,但如果您能够发现任何看起来像您的SOAP消息的片段(应该很容易发现),那么您可以通过右键单击并选择来快速过滤到该对话'关注TCP Stream'。 然后,您可以在弹出窗口中查看您编写的SOAP服务与Silverlight客户端之间的整个对话。 如果一切正常,请关闭弹出窗口。 作为一个额外的好处,wireshar

Android默认情况下不提供TextView的合理结果。 您可以使用以下库并实现适当的aligntment。 https://github.com/navabi/JustifiedTextView Android Does not provide Justified aligntment of TextView By default. You can use following library and achieve proper aligntment. https://github.com/

你的代码适合我: class apples { public static void main(String args[]) { System.out.println("Hello World!"); } } 我将它下载到c:\ temp \ apples.java。 以下是我编译和运行的方式: C:\temp>javac -cp . apples.java C:\temp>dir apples Volume in drive C is HP_PAV

12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构http://en.wikipedia.org/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar

这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值