合并Java中的两个数组

时间:2020-09-03 07:50:40

标签: java

我正在尝试将两个不同的数组合并为一个合并的数组。我尝试过barplot(table(res$n), col=2, main="Extreme rainfalls", xlab="Duration", ylab="Frequency") ,但随后收到一条错误消息,指出数字已使用但从未调用过。

下面是我到目前为止的代码。

ArrayList

2 个答案:

答案 0 :(得分:1)

这是合并两个数组的方法。

user_id | name    | home_address | office_address
1       | Albert  |   a          |   b
2       | Anthony |   c          | null

输出 运行:

static class Solution {
    public int findLength(int[] A, int[] B) {
                    
        return A.length+B.length;                        
    }
    
    public int[] getMergedArray(int[] A, int[] B){
        
        int arrayLength=this.findLength(A, B);
        int mergedArray[]= new int[arrayLength];
        
        
        //copying first array data
        for (int i = 0; i < A.length; i++) {
            
            mergedArray[i]=A[i];
        }
                   
        for (int i = A.length; i < arrayLength; i++) {
                            
            mergedArray[i]=B[i-A.length];
        }            
    
        return mergedArray;
    }
}

public static void main(String[] args) {
    Solution solution = new Solution();
    int[] row1 = {1,2,3,4,5,6};
    int[] row2 = {7,8,9,10,11,12};
    solution.findLength(row1,row2);
    System.out.println("First Array");
    for (int i = 0; i < row1.length; i++) {
        
        System.out.println(" "+row1[i]);
    }
    System.out.println("Second Array ");
    for (int i = 0; i < row2.length; i++) {
        
        System.out.println(" "+row2[i]);
    }
    System.out.println("Merged Array ");
    
    int mergedArray[]=solution.getMergedArray(row1, row2);
    for (int i = 0; i < mergedArray.length; i++) {

               System.out.println(" "+mergedArray[i]);
    }
}

答案 1 :(得分:0)

您可以像合并它们一样复制数组

body {
  background-color: black; 
}

.figure {
  position: relative;
  display: flex;
  width: 100%;
  height: auto;
  justify-content: center;
}

.figure .figcaption {

  font-size: 25px; 
  line-height: 0;
  color: white;
  z-index: 1;
  margin: 0;
  padding: 0;
  position: absolute;
  bottom: -15%;
  left: 15%;
}

.figure img {
  display:block;
  width: 50%; 
}