diff --git a/Main.java b/Main.java new file mode 100644 index 0000000..9c22180 --- /dev/null +++ b/Main.java @@ -0,0 +1,92 @@ +/** + * @Filename - Main.java + * @Description - Entry point of the application + * @Author - Aditi Agrawal + */ +import java.util.Arrays; +import java.util.Scanner; + + +public class Main { + public static void main(String [] args){ + + Scanner sc = new Scanner(System.in); + System.out.println("Enter a string to perform operations"); + String original = sc.nextLine(); + MyString obj = new MyString(original); + + + while(true) { + System.out.println("Select the operation you want to perform"); + String[] arr = {"Exit()","append()", "countWords()", "replace()", "isPalindrome()", "splice()", "split()", "maxRepeat()", "sort()", "shift()", "reverse()"}; + for (int i = 0; i < arr.length; i++) { + System.out.println(i + "->" + arr[i]); + } + + int choice = sc.nextInt(); + sc.nextLine(); + if(choice == 0){ + System.out.println("Exit"); + break; + } + switch (choice) { + case 1: + System.out.println("Enter string to append"); + String temp = sc.nextLine(); + System.out.println("Output:"); + System.out.println(obj.appendstrings(temp)); + break; + case 2: + System.out.println("Output:"); + System.out.println(obj.countwords()); + break; + case 3: + System.out.println("Enter the character you want to replace"); + char first = sc.nextLine().charAt(0); + System.out.println("Enter the character you want to replace with:-"+first); + char second = sc.nextLine().charAt(0); + System.out.println("Output:"); + System.out.println(obj.replace(first,second)); + break; + case 4: + System.out.println("Output:"); + System.out.println(obj.isPalindrome()); + break; + case 5: + + System.out.println("Enter start index to remove from"); + + int starts = sc.nextInt(); + sc.nextLine(); + System.out.println("Enter length to remove"); + int lengths = sc.nextInt(); + System.out.println("Output:"); + System.out.println(obj.splice(starts, lengths)); + break; + case 6: + System.out.println("Output:"); + System.out.println(Arrays.toString(obj.split())); + break; + case 7: + System.out.println("Output:"); + System.out.println(obj.maxrepeat()); + break; + case 8: + System.out.println("Output:"); + System.out.println(obj.sorting()); + break; + case 9: + System.out.println("Enter number of characters you want to shift"); + int place = sc.nextInt(); + System.out.println("Output:"); + System.out.println(obj.shift(place)); + break; + case 10: + System.out.println("Output:"); + System.out.println(obj.reverse()); + break; + } + System.out.println("----------------------------------------------------------------------------"); + } + } +} \ No newline at end of file diff --git a/MyString.java b/MyString.java new file mode 100644 index 0000000..183c86a --- /dev/null +++ b/MyString.java @@ -0,0 +1,199 @@ +/** + *@filename - MyString.java + *@description - This will perform most of the string operations + *@author - Aditi Agrawal +*/ + +import java.util.Arrays; + +public class MyString{ + + String original; + MyString(String original){ + this.original=original; + } + + + //append + String appendstrings(String st){ + original=original+st; + return original; + } + + + + + //countwords + int countwords(){ + if(original.length()==0){ + return 0; + } + boolean isword=false; + int count=0; + for(int i=0;ioriginal.length() || length<=0){ + return original; + } + + String temp=""; + for(int i=0;i=start && i=original.length())break; + int j=i; + while(j= 'a' && ch <= 'z') { + freq[ch - 'a']++; + } + } + + StringBuilder sb = new StringBuilder(); + for (int i=0;i<26;i++) { + for (int j=0;jmaxi){ + maxi=freq[ch]; + character=ch; + } + } + return character; + } + + + //reverse + String reverse(){ + char[] arr = original.toCharArray(); + int i=0; + int j=arr.length-1; + while(i