【问题标题】:Add packets to array将数据包添加到阵列
【发布时间】:2016-12-28 05:43:58
【问题描述】:

我创建的方法应该在数组索引

    public static void addPacketsToTable(byte[] byteTable, long packetSize, long diskSpace) throws IOException {
        long packet = fetchPacketSize();//size of packet (it is 5)
        long space = fetchDiskSpace();//free space on my disk
        for(int i = 0; i < byteTable.length; i++) {//for another packet
            while(packet < space && byteTable[i] < 4) {
                packet *= 2;
                while(byteTable[i] > 4) {
                    packet *= 3;
                }
                System.out.println(packet);
            }
        }
    }

【问题讨论】:

  • 也许您可以提供更多上下文。我实际上不知道您的代码应该做什么;或者它应该用于什么......
  • 这个想法是将数据包值 *2 从索引 0 乘以 4,然后将该值乘以 *3 直到空闲空间消失

标签: java arrays packets


【解决方案1】:

据我了解的问题,一个简单的解决方案可以是:

public static void addPacketsToTable(byte[] byteTable, long packetSize, long diskSpace) throws IOException {

    long packet = fetchPacketSize(); //size of packet (it is 5)
    long space = fetchDiskSpace(); //free space on my disk

    for (int i = 0; i < byteTable.length; i++) { //for another packet

        if (i < 4)
            packet *= 2;
        else
            packet *= 3;

        // packet size overflows disk
        if (packet > space)
            break;

        System.out.println(packet);

    }
}

【讨论】:

  • 我犯了一个错误,现在我明白了。我需要索引,而不是索引中的值......我的错。我该如何解决?有解决办法吗?
猜你喜欢
  • 2015-06-21
  • 1970-01-01
  • 2014-03-02
  • 1970-01-01
  • 2021-03-12
  • 2015-10-10
  • 1970-01-01
  • 2017-06-15
  • 1970-01-01
相关资源
最近更新 更多