Answer:
//To pass in a string, and pass in a pivot string, and at that moment print in obligatory sequence, the string after pivot string till last as first string, and published beforehand the left slice of string.
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner s2 = new Scanner(System.in);
System.out.println("Enter the parent String:");
String f2 = s2.nextLine();
System.out.println("Enter pivot(child string):");
String piv1 = s2.nextLine();
int start2 = f2.indexOf(piv1);
int end2 = piv1.length()+start2;
if (start2 == -1){
System.out.println("Error: child string(Pivot) not discovered.");
return;
}
String first2 = f2.substring(0,start2-1);
String second2 = f2.substring(end2);
if (f2.charAt(start2-1)==' '){
System.out.println(second2 + " " + piv1 + " " + first2);
return;
}
System.out.println(second2 + piv1 + first2);
}
}
Explanation:
Please check the answer section.