JAVA练习:调整字符串

1.题目:

2.实现截图:

3.实现代码:

import java.util.Scanner;

public class tjzfc {
    public static void main(String[] args){
        System.out.println("请输入字符串B:");
        Scanner sc=new Scanner(System.in);
        String b=sc.next();
        System.out.println("请输入字符串A:");
        Scanner sc1=new Scanner(System.in);
        String a=sc.next();
        if(a.equals(b)){
            System.out.println("A和B相同");
        }else{            String temp=tz(a);
        for(int i=0;i<a.length()-1;i++){
            //System.out.println(temp);
            if(i==a.length()-1){System.out.println("若干次调整后,A也没有变成B");break;}
            if(pd(temp,b)){
                System.out.println("调整"+(i+1)+"次后A和B相同");
                break;
            }
            temp=tz(temp);
        }
        }
    }

    public static String tz(String a){
        String tou=a.substring(0,1);
        String wei=a.substring(1,a.length());
        String newa=wei+tou;
        return newa;
    }
    public static boolean pd(String a,String b){
        if(b.equals(a)){
            return true;
        }else{
            return false;
        }
    }
}

将悲伤的事对半分吧,将快乐的事拼凑成双吧