dimanche 21 février 2021

Returning another String from 2 input sentence that are zipped together

So I am trying to return another String from 2 input sentences zipped together. If the 2 sentences are identical in length it will produce an actual output. If the two input sentences are not identical in length then it will just return an empty string. Here is my code so far but I can't figure out how to zip the words correctly could someone help me. BTW it would be nice if you could help me by doing this recursively because I'm trying to practice that.

Ex:

Zippppp("ABC", "123") will return "A1B2C3"
Zippppp("AD", "CCC") will return “”
public class Zippppp
{
  
    public Zippppp(String a, String s){
        
        int l1 = a.length();
        int l2 = s.length();
        
        
        if(l1 == l2){ 
            for(int i = 0; i > l1; i++){
                
            System.out.print( a.substring(0, 1) + s.substring(0, 1));
            
        }
        }
        
        
    }
    
   
    public static void main(String args[ ]){
        
        
        Zipppppsv = new Zippppp("ABC", "123");
        
        System.out.print(sv);
        
        
    }
}

Aucun commentaire:

Enregistrer un commentaire