Merge two strings letter by letter in Java?

前端 未结 7 1281
梦毁少年i
梦毁少年i 2021-01-21 22:05

Given two strings, A and B, create a bigger string made of the first char of A, the first char of B, the second char of A, the second char of B, and so on. Any le

相关标签:
7条回答
  • 2021-01-21 23:05

    Here is my Approach, feedback is most welcome

    void printPattern(String str, String str1){
        int length1 = str.length();
        int length2 = str1.length();
        int i =0;
        String output ="";
        while(length1 > 0 && length2 > 0){
             output += (str.charAt(i)) ;
             output += (str1.charAt(i)) ;
            length1-- ; length2-- ; i++;
        }
        System.out.println(output);
    }
    
    0 讨论(0)
提交回复
热议问题