java中的错误划分
发布时间:2020-12-15 05:04:58 所属栏目:Java 来源:网络整理
导读:参见英文答案 Integer division: How do you produce a double?????????????????????????????????????10个 我正在划分两个int值,我希望得到一个双倍的值.但它的工作非常奇怪,它在分割之前具有正确的值,但它没有给出正确的答案. public void Analyse() { for
参见英文答案 >
Integer division: How do you produce a double?????????????????????????????????????10个
我正在划分两个int值,我希望得到一个双倍的值.但它的工作非常奇怪,它在分割之前具有正确的值,但它没有给出正确的答案. public void Analyse() { for (FlowPacket fp : this.flow.GetAll()) { if (fp.direction==1){ this.sentPackets++; this.sentLength = this.sentLength + fp.packetLength; } else{ this.receivedPackets++; this.receivedLength = this.receivedLength + fp.packetLength; } } if(this.receivedPackets==0) this.receivedPackets = 1; } public double CalcRatio() { return (this.sentPackets/this.receivedPackets); } – – – – – – – – – – – – – – 主要 – – – – – – – – – – – ———– System.out.print("Sent packets: " + analyser.getTotalSentPackets() + ","); System.out.print("Received packets: " + analyser.getTotalReceivedPackets() + ","); System.out.print("ratio: " + analyser.CalcRatio() + ","); —————————- outout ——————— ——— Sent packets: 2694,Received packets: 5753,ratio: 0 解决方法(double)this.sentPackets/this.receivedPackets ……应该解决它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |