Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class Assignment5_WIP {
- public static void main(String[] args) {
- Scanner scanner = new Scanner(System.in);
- System.out.println("Enter the first String: ");
- String string1 = scanner.nextLine();
- int lengthofall = string1.length();
- System.out.println("Enter the pivot String");
- String string2 = scanner.nextLine();
- Boolean flag = string1.contains(string2);
- if(string2 == null || flag == false) {
- System.out.println("Error: Pivot String not found.");
- }
- else {
- int indexof = string1.indexOf(string2); //start of pivot string
- int lengthof = string2.length(); //total length of string
- String test = string1.substring(indexof, (indexof + lengthof)); //substring of only pivot
- String front = string1.substring(0, indexof);
- String back = string1.substring((indexof + lengthof) ,lengthofall );
- System.out.println(back + string2 + front);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement