第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

大神求解,初學(xué)java,

大神求解,初學(xué)java,

慕的地8271018 2018-07-05 18:22:26
在java中創(chuàng)建一個(gè)方法,調(diào)用方法之后需要從方法中返回兩個(gè)數(shù)組,怎樣才能辦到
查看完整描述

2 回答

?
慕斯王

TA貢獻(xiàn)1864條經(jīng)驗(yàn) 獲得超2個(gè)贊

方式有很多種,
1.二維數(shù)組的方式
2.Vector(不定長(zhǎng)數(shù)組)嵌套的方式
3.Vector內(nèi)套數(shù)組
3.List>的方式
4.List>的方式
……
下面我用兩種方式給你一個(gè)簡(jiǎn)單的demo:
1.二維數(shù)組

 // 創(chuàng)建定長(zhǎng)二維數(shù)組
    public static int[][] getArrays(){
        // 創(chuàng)建二維數(shù)組,2 -- 表示外層數(shù)組的長(zhǎng)度,3表示里層數(shù)組的長(zhǎng)度
        int[][] a = new int[2][3];
        int[] b = {1, 2, 3};
        int[] c = {4, 5, 6};
        a[0] = b;
        a[1] = c;
        return a;
    }

    // 二維數(shù)組
        int[][] a = getArrays();
        for(int i = 0; i < a.length; i++){
            int[] b = a[i];
            for(int j = 0; j < b.length; j++){
                System.out.print(b[j] + " ");
            }
            System.out.println(" ");
        }

        System.out.println("\n\n");

2.Vector內(nèi)套數(shù)組的方式

 // 外層使用不定長(zhǎng)數(shù)組
    public static Vector<int[]> getVectors(){
        Vector<int[]> vector = new Vector<>();
        int[] b = {1, 2, 3};
        int[] c = {4, 5, 6};
        vector.add(b);
        vector.add(c);
        return vector;
    }

    // vector
        Vector<int[]> vector = getVectors();
        // 獲取迭代器
        Iterator<int[]> iterator = vector.iterator();
        while (iterator.hasNext()) {
            int[] b = iterator.next();
            for(int c : b){
                System.out.print(c + " ");
            }
            System.out.println(" ");
        }


查看完整回答
反對(duì) 回復(fù) 2018-07-16
?
慕婉清6462132

TA貢獻(xiàn)1804條經(jīng)驗(yàn) 獲得超2個(gè)贊

方法返回值只能返回一個(gè)對(duì)象,如果你想返回兩個(gè)數(shù)組(其實(shí)就是兩個(gè)對(duì)象了),可以將兩個(gè)數(shù)組封裝到一個(gè)類(lèi)中返回這個(gè)類(lèi)即可,也可以通過(guò)返回list來(lái)解決


查看完整回答
反對(duì) 回復(fù) 2018-07-16
  • 2 回答
  • 0 關(guān)注
  • 372 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)