Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  KtdYU5s4.java
Language: JAVA
Code:
public class KtdYU5s4 {

    public static void main(String[] args) {
       
       int[] vett1=new int[3];
       int[] vett2=new int[4];
       int[] vettF=new int[7];

vett1[1]=1;
vett1[-5]=1;
vett1[7]=1;

vett2[9]=1;
vett2[2]=1;
vett2[-5]=1;
vett2[91]=1;

     vettF=fusione(vett1,vett2);
    }

    public static int[] fusione(int[] v1,int[] v2){
     
      int[] vett=new int[v1.length+v2.length];
      int j=0,k=0;     

      for(int i=0;i<vett.length;i++){
     
     if(j<v1.length&&k<v2.length){          
        if(v1[j]<v2[k]){
          vett[i]=v1[j];
            j++;
        }
        else{
          vett[i]=v2[k];
          k++;
        }
         }
     else{
        if(j<v1.length){
          vett[i]=v1[j];
             j++;
        }

        if(k<v2.length){
             vett[i]=v2[k];
             k++;
           } 
     }
     
     return vett;
     }
    }     

}     
Comments: