Answer:
//To enter a string, and enter a pivot string, and then print in required sequence, the string from pivot string to last as first string, and printed before the left portion of string.
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner s1 = new Scanner(System.in);
System.out.println("Enter Main String:");
String f1 = s1.nextLine();
System.out.println("Enter pivot(string):");
String piv = s1.nextLine();
int start1 = f1.indexOf(piv);
int end1 = piv.length()+start1;
if (start1 == -1){
System.out.println("Error: Sub string(Pivot) cannot be found.");
return;
}
String first1 = f1.substring(0,start1-1);
String second1 = f1.substring(end1);
if (f1.charAt(start1-1)==' '){
System.out.println(second1 + " " + piv + " " + first1);
return;
}
System.out.println(second1 + piv + first1);
}
}
Explanation:
Please check the answer section