Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package FinalExam03August2019Group2;
- import java.util.Scanner;
- public class StringManipulatorGroup2 {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- String string = scan.nextLine();
- String line = scan.nextLine();
- while (!line.equals("Done")){
- String[] command = line.split(" ");
- switch (command[0]){
- case "Change":
- string = string.replace(command[1] , command[2]);
- System.out.println(string);
- break;
- case "Includes":
- String includes = command[1];
- if (!string.contains(includes)){
- System.out.println("False");
- }else {
- System.out.println("True");
- }
- break;
- case "End":
- String endsWith = string.substring(string.lastIndexOf(" "));
- String givenEnd = command[1];
- if (endsWith.equals(givenEnd)){
- System.out.println("True");
- }else {
- System.out.println("False");
- }
- break;
- case "Uppercase":
- string = string.toUpperCase();
- System.out.println(string);
- break;
- case "FindIndex":
- int num = string.indexOf(command[1]);
- System.out.println(num);
- break;
- case "Cut":
- int startIndex = Integer.parseInt(command[1]);
- int lenght = Integer.parseInt(command[2]);
- string = string.substring(startIndex , lenght + startIndex);
- System.out.println(string);
- break;
- }
- line = scan.nextLine();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement