如何获得二维数组中的百分比 [英] How can I get the percentage in two-dimensional array

查看:128
本文介绍了如何获得二维数组中的百分比的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要有人可以帮我找到二维数组的百分比。我有一个data.txt给我的值和驱动程序。



I need someone can help me to find the percentage of a two-dimensional array. I have a data.txt which gives me the values and the driver.

for (int i = 0; i < index; i++){
            totalArea+= myRectangle[i].getArea();
            
            
        System.out.println(i + " " + " Rectangle " + myRectangle[i]);  
        
        grantTotal += myRectangle[i].getArea();





我试过的:



我正在尝试使用for循环,但是我得到了无穷大。我需要一些帮助。这应该是什么样子



0矩形L:12.4 W:13.2面积:163.68%总面积42.8

1矩形L:11.8 W:6.7面积:79.06%总面积20.7

2矩形L:7.1 W:5.9面积:41.89%总面积11.0

3矩形L:3.8 W:0.2面积:总面积的0.76%0.2

4矩形L:9.6 W:10.1面积:总面积的96.96%25.4



What I have tried:

I was trying using the for loop but I get infinity. Please I need some help.This is what it should look like

0 Rectangle L : 12.4 W : 13.2 Area : 163.68 % of total area 42.8
1 Rectangle L : 11.8 W : 6.7 Area : 79.06 % of total area 20.7
2 Rectangle L : 7.1 W : 5.9 Area : 41.89 % of total area 11.0
3 Rectangle L : 3.8 W : 0.2 Area : 0.76 % of total area 0.2
4 Rectangle L : 9.6 W : 10.1 Area : 96.96 % of total area 25.4

推荐答案

如果你的循环永远不会结束你会得到无穷大。你不清楚你想要的百分比,但唯一的答案是,正确的外观会增加你想要计算百分比的数字。



我假设index是数组的长度?
You get infinity if your loop never ends. You're not clear what you want a percentage of, but the only answer is, a proper look that adds up the numbers you want to calculate a percentage of.

I assume index is the length of your array?


这篇关于如何获得二维数组中的百分比的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆