Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.00 KB | None | 0 0
  1. package FinalExam03August2019Group2;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class StringManipulatorGroup2 {
  6.     public static void main(String[] args) {
  7.         Scanner scan = new Scanner(System.in);
  8.  
  9.         String string = scan.nextLine();
  10.  
  11.         String line = scan.nextLine();
  12.  
  13.         while (!line.equals("Done")){
  14.             String[] command = line.split(" ");
  15.  
  16.             switch (command[0]){
  17.                 case "Change":
  18.                     string = string.replace(command[1] , command[2]);
  19.                     System.out.println(string);
  20.                     break;
  21.                 case "Includes":
  22.                     String includes = command[1];
  23.                     if (!string.contains(includes)){
  24.                         System.out.println("False");
  25.                     }else {
  26.                         System.out.println("True");
  27.                     }
  28.                     break;
  29.                 case "End":
  30.                     String endsWith = string.substring(string.lastIndexOf(" "));
  31.                     String givenEnd = command[1];
  32.                     if (endsWith.equals(givenEnd)){
  33.                         System.out.println("True");
  34.                     }else {
  35.                         System.out.println("False");
  36.                     }
  37.                     break;
  38.                 case "Uppercase":
  39.                     string = string.toUpperCase();
  40.                     System.out.println(string);
  41.                     break;
  42.                 case "FindIndex":
  43.                     int num = string.indexOf(command[1]);
  44.                     System.out.println(num);
  45.                     break;
  46.                 case "Cut":
  47.                     int startIndex = Integer.parseInt(command[1]);
  48.                     int lenght = Integer.parseInt(command[2]);
  49.                     string = string.substring(startIndex , lenght + startIndex);
  50.                     System.out.println(string);
  51.                     break;
  52.             }
  53.  
  54.             line = scan.nextLine();
  55.         }
  56.     }
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement