Transform first string into second letter by letter , starting from the first one use Java

Viewed 39

You will be given two strings. Transform the first string into the second one, letter by letter, starting from the first one. After each interaction, print the resulting string only if it is unique. Note: the strings will have the same length. For input Kitty Doggy
Output should be Ditty Dotty Dogty Doggy I got only Ditty Ditty Ditty Ditty, how to fix it ?

My solution is

import java.util.Objects;
import java.util.Scanner;
public class MutantStrings {
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        String str1 =scan.nextLine();
        String str2 = scan.nextLine();

        String m_str = " ";
        for(int i=0;i<str1.length();i++){

            String f_str =str1.substring(1);
            m_str =str2.substring(0,1) + f_str;
            if (!str1.equals(str2)){
                System.out.println(m_str);
               
            }

        }



    }
}
0 Answers
Related