亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何使用兩個不同長度的數組打印表中的值

如何使用兩個不同長度的數組打印表中的值

翻過高山走不出你 2021-12-22 20:19:04
我想創建一個包含兩個不同維度的不同數組的表,但執行后它沒有給我正確的輸出。我有以下代碼:String rowHeadingkeys[] = new String[] {"heading1","heading2","heading3","heading4","heading5","heading6","heading7","heading8"};String rowValuekeys[] = new String[] {"Text1","Text2","Text3","Text4","Text5",                                    "Text6","Text7","Text8","Text9","Text10",                                    "Text11","Text12","Text13","Text14","Text15",                                    "Text16","Text17","Text18","Text19","Text20",                                    "Text21","Text22","Text23","Text24"};    for(int i = 0;i<rowHeadingkeys.length;i++) {        if(rowHeadingkeys!=null) {            patientMonitoringTable.addCell(createCell(rowHeadingkeys[i],                    PDFUtil.BOLD_FONT,1,Element.ALIGN_LEFT));            for(int j = 0;j<rowValuekeys.length/rowHeadingkeys.length;j++) {                patientMonitoringTable.addCell(createCell(svo.getFields().get(rowValuekeys[j]).getValue(),                        PDFUtil.FONT,1,Element.ALIGN_LEFT));            }        }}我想讓它像下面這樣:| heading1 | Text1  | Text2  | Text3  |    | heading2 | Text4  | Text5  | Text6  |    | heading3 | Text7  | Text8  | Text9  |    | heading4 | Text10 | Text12 | Text13 |    | heading5 | Text14 | Text15 | Text16 |    | heading6 | Text17 | Text18 | Text19 |    | heading7 | Text20 | Text21 | Text22 |    | heading8 | Text23 | Text24 | Text24 |如何實現這一目標?
查看完整描述

2 回答

?
守候你守候我

TA貢獻1802條經驗 獲得超10個贊

我猜你會得到 Text1 | 文本 2 | 文本 3 | 對于每個標題。


您不應該在每個循環中分配 j = 0。在兩個 for 循環和內部 for 循環之外初始化一個 int index=0 應該是這樣的。


for(int j = index; j<index + (rowValuekeys.length/rowHeadingkeys.length);j++){


}

index+=rowValuekeys.length/rowHeadingkeys.length;

編輯:


更好的解決方案是:


int innerIndex = 0;

for(int i = 0;i<rowHeadingkeys.length;i++) {


    if(rowHeadingkeys!=null) {


        patientMonitoringTable.addCell(createCell(rowHeadingkeys[i],

                PDFUtil.BOLD_FONT,1,Element.ALIGN_LEFT));


        for(int j = 0;j<rowValuekeys.length/rowHeadingkeys.length;j++) {

      if(innerIndex < rowValuekeys.length)

            patientMonitoringTable.addCell(createCell(svo.getFields().get(rowValuekeys[innerIndex]).getValue(),

                    PDFUtil.FONT,1,Element.ALIGN_LEFT));

           innerIndex++;

        }


    }

}


查看完整回答
反對 回復 2021-12-22
?
慕田峪9158850

TA貢獻1794條經驗 獲得超8個贊

如果您想要第 1 個項目的第 2 個列表中的 3 個項目:


for(int i = 0; i < rowHeadingkeys.length;i++) {


    if(rowHeadingkeys!=null) {


        patientMonitoringTable.addCell(createCell(rowHeadingkeys[i],

                PDFUtil.BOLD_FONT,1,Element.ALIGN_LEFT));


        for(int j = 0; j < 3; j++) {


            patientMonitoringTable.addCell(createCell(svo.getFields().get(rowValuekeys[3 * i + j]).getValue(),

                    PDFUtil.FONT,1,Element.ALIGN_LEFT));

        }

    }

}


查看完整回答
反對 回復 2021-12-22
  • 2 回答
  • 0 關注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號