io un controllo sulle dimensioni e sui parametri in input lo farei
Codice PHP:
 public void mainProva(){
        
int first []= {1,2,3,4,5,6};
        
int second []= {7,8,9,10,11,12};
        
        
int third[] = sommaElem(firstsecond); 
        
        
second sommaElem(thirdfirst);
    }
    public  
int[] sommaElem(int[] firstArrayint secondArray[]) {
        
        
int ret[] = null
        if (
firstArray == null || secondArray == null){
            throw new 
IllegalArgumentException("Input cannot be null");
        }
        
        if (
firstArray.length != secondArray.length || firstArray.length == 0){
            throw new 
IllegalArgumentException("Input arrays must have same length and length must be greater than 0");
        }
        
        
ret = new int[firstArray.length];
        
        for (
int index 0index firstArray.lengthindex++) {
            
ret[index] = firstArray[index] + secondArray[index];
        }
        return 
ret;
    } 
come vedi il valore di ritorno l'ho usato come parametro nella chiamata successiva