From 3befa70add6fa8671f87f8fd093099e534f7e0ea Mon Sep 17 00:00:00 2001 From: Priyansh Singh Date: Wed, 8 Oct 2025 15:22:34 +0530 Subject: [PATCH 1/5] Completed Task_1 When the program is run, the user will first enter a string. After that, the program should ask the user which operation they want to execute on the string. The available operations are listed below: Append, CountWords, Replace, isPalindrome, Splice, Split, MaxRepeatingCharacter, Sort, Shift, and Reverse. Each method should perform its respective operation based on the user's input. --- MyString.class | Bin 0 -> 2703 bytes MyString.java | 222 +++++++++++++++++++++++++++++++++++++++++++++++++ StringOp.class | Bin 0 -> 3675 bytes 3 files changed, 222 insertions(+) create mode 100644 MyString.class create mode 100644 MyString.java create mode 100644 StringOp.class diff --git a/MyString.class b/MyString.class new file mode 100644 index 0000000000000000000000000000000000000000..b2aff31ef5d5d5bbede90e7dcf732f947cf9bebb GIT binary patch literal 2703 zcmah~Yj6`)6#g!4v)go02(&6tT$O4HC8azHv^>OEG?oey1VK@kWTi`!-MG7fR#X&x zzZFsNg^C)*$0%y*fZ*u(gu(GW>gedGKm6h7_|MUq=sCMvn+}Y2=H%SooO8bO_|DD2 z(%u6A=Hk&XhM_`2rGhGi1V*gW)@#if&0O2Oc+EOJHCd7g&VoG^2FH|g5CmTeD1!U)D6 zDR6xBs3r_NN8fd3MNpJrrzr= zGE7}ybhObgr`(!zKUKkLj1|&yIo(XlXcVXmC-n?<+{>lh6oJUpm>Re8rXOm9Wv3k(Q>nSrV(L;om(fzX=aTByY%N7? zkuja>o=#rfda6fVqGb#-ZChDgMk|#(Bc>)ZMv6K=1Zfuew9;3(jNv2s?U2zXFn(rC z?b3RUY(C47I@Lnn@j<{jl;$jQw(Oz4#Itd;>Au^z%vJwQkY*N)OUCKcs+K8S$$H&( z{7MFjKZDxeLVfAzHC!2IQiA^2`>ec8(JUjS^SmW2RB#r~rjGKk5Z8+4-KE7M5UR_oE@mYLGr z6^7eQC&$%H*I_;-j=~Wc%LUZILzxMb)W zdR!;Maij%QZYANyWoQBu{s(3QB}`Beq!gq-8zex9b&b;M=f6O!JLp^igm8lpK#|rsYp|qk=1O)gUx~>9@)& zaFc>-IM#66r`|xg%@m#)M~TE@F&Wp<6PYkmmTmJoTRGn2lXzG+D7cXWRHZVOqf5A% z=-SoihasG}m8MFM<+tP9e0Gg)FVog!=%zBO@#|R^z3|A_q>+d+Jn3qwo-QpH*oTuu z_msZSVCUfj05N{osPHo^%XM5^%XR5)x0QB|4Pk2-_hOrb`fYhGkO^x0k<#fuSGtY#MMzcP1>dte$+X{m8V-ZiYB6>&xj!F)uIN|6OV? z-nc!clct&#^-I4H+K*JGb9xZzbkI;Me-=?%! zeyLD#6aAv{AAizsDgWgWAXmMT~8lRK!U|G}Mo%*(o;iZM2AqtS1M$InXVEo)+jC zfu0%Y*@12k^xQzt5A=dS#|f1{JLWO+iu&D@IQ}Hz3TjB&NX{ckk=#SFgXA@mH%Q(k zIZW~s$#0xwqO63bB039y&!%fSox7KV5M<%+)7bEQIuhWDiXv9ER`SiIuK#_(-AT0@+1tJG8*s+Ef9DU?1TE2~gCM9MCd-X@hVl=ibvZ%|*W z+*B(UaYdo@6n%R&NoS$-AX{9^X_fBc;}-9DJw?Bsr#Z}<=C5d{^LFaS4vfMBsKrAx z_=nMeotT72F%6HA#p8%$7dr6-E!&gyVn0P4E1(BY!@)Dyh~3zNXDQxu*ox;V+6xrn zMSO`p_#Q9gXS{-6@G5>oKT3Fwh`m=-W1kp>*Tq=u7Y#TdCgTk;1#gP!cuUO0+hRW6 z5gm9}bmBdc#QS174vJMcBv#|F(D0#1<0H|Hk3|nY6%IZVefV5#!WUvQz7#j$D{%|H z7PsRYu?^pf?f6dY!VjW=A8`j&I~K>3&>%sQ5D|Z2Pu<8^XnZIXstbq1MC3cY=G=w5 XNy|i)dq}oZYk)AF9;DKC;)H(yitX1w literal 0 HcmV?d00001 diff --git a/MyString.java b/MyString.java new file mode 100644 index 0000000..4881d91 --- /dev/null +++ b/MyString.java @@ -0,0 +1,222 @@ +import java.util.*; + +class StringOp{ + String currentString = new String(""); + StringOp(String s){ + this.currentString=s; + } + //Function to append the String + public String append(String given_String) { + if (currentString.length()>0) //adding spaces between words + currentString+=' '; + currentString+=given_String; + return currentString; + } + + //function to count the words in the string + public int countWords() { + String temp_st = new String(""); //temporary string to store the word + int word_count=0; + for (char ch : currentString.toCharArray()) { + if (ch == ' ' || ch==',') { + if (temp_st.length() > 0) { + word_count++; //adding the word count + temp_st=""; //making the string empty + } + } else { + temp_st+=ch; //adding character in string + } + } + if (temp_st.length() > 0) + word_count++; //adding last word count + return word_count; + } + + //function to reverse the string + public String reverseString() { + char[] char_array = currentString.toCharArray(); // Convert to char array + char[] reversed = new char[char_array.length]; // Create array for reversed characters + + for (int i = char_array.length - 1, j = 0; i >= 0; i--, j++) { + reversed[j] = char_array[i]; + } + + currentString = new String(reversed); //converted the char[] in string + return currentString; + } + + //function to replace the character in the string + public String replaceChar(char a,char b){ + String temp_string=new String(""); //making temp empty string for storing the char + for (char ch: currentString.toCharArray()){ + if (ch==a){ + temp_string+=b; + } + else{ + temp_string+=ch; + } + } + currentString=temp_string; + return currentString; + } + //function to delete the substring + public String stringSlice(int start,int end){ + if (start < 0 || end > currentString.length() || start > end) { //valid checks befor slicing + return "0"; + } + currentString=currentString.substring(0,start)+currentString.substring(end); + return currentString; + } + //function to split string in array + public List splitString(){ + List word_List = new ArrayList<>(); + String st = new String(""); + for (char ch : currentString.toCharArray()) { + if (ch == ' ') { + if (st.length() > 0) { + word_List.add(st); + st=""; + } + } else { + st+=ch; + } + } + if (st.length() > 0) + word_List.add(st); + return word_List; + } + //function to check the string is pallindrome or not + public boolean isPalindrome() { + char[] st=currentString.toLowerCase().toCharArray(); // Convert to char array + int left=0; + int right=st.length-1; + while(left<=right){ + if (st[left]!=st[right]){ + return false; + } + left++; + right--; + } + return true; + } + + //function to shift the char of the string + public String stringShift(int n){ + if (n<0) + return currentString ; + int len = currentString.length(); + if (len == 0) return currentString; + n = n % len; + String s = currentString; + String shifted = s.substring(len - n) + s.substring(0, len - n); + currentString = new String(shifted); + return currentString; + + } + + //function to find the repeating char in string + public void maxRepeat() { + String temp = currentString.toLowerCase(); + int[] freq = new int[256]; //intitalizing the frequency array + for (char c : temp.toCharArray()) { + freq[c]++; + } + + char maxChar = ' '; + int maxCount = 0; + for (char c : temp.toCharArray()) { + if (c!=' '){ + if (freq[c] > maxCount) { + maxCount = freq[c]; + maxChar = c; + } + } + } + + System.out.println("Character with maximum occurrence: " + maxChar + " -> " + maxCount); + } + + //function to sort the string + public String sortString() { + char[] sstring = currentString.toLowerCase().toCharArray(); + Arrays.sort(sstring); + currentString = new String(sstring); + return currentString; + } +} + +class MyString{ + public static void main(String[] args) { + Scanner obj = new Scanner(System.in); + int option = 0; + + System.out.print("Enter the initial string: "); + StringOp str = new StringOp(obj.nextLine()); + while (option != 11) { + System.out.println("\nSelect the Operation:"); + System.out.println("1. Append the string"); + System.out.println("2. Count the words"); + System.out.println("3. Replace the character"); + System.out.println("4. Check Palindrome"); + System.out.println("5. Slicing the string"); + System.out.println("6. Split the String"); + System.out.println("7. Maximum Repeating Character"); + System.out.println("8. Sort the String"); + System.out.println("9. Shift character in string"); + System.out.println("10. Reverse the string"); + System.out.println("11. Exit"); + System.out.print("Enter your choice: "); + option = obj.nextInt(); + obj.nextLine(); + + switch (option) { + case 1: + System.out.print("Enter the string to append: "); + System.out.println("Appended String: " + str.append(obj.nextLine())); + break; + case 2: + System.out.println("Word count: " + str.countWords()); + break; + case 3: + System.out.println("Enter the character to replace :"); + char a=obj.next().charAt(0); + System.out.println("Enter the character to replace with:"); + char b=obj.next().charAt(0); + System.out.println("String:"+str.replaceChar(a,b)); + break; + case 4: + System.out.println(str.isPalindrome()); + break; + case 5: + System.out.println("Enter the start and end (s,e) to delete:"); + int start=obj.nextInt(); + int end=obj.nextInt(); + System.out.println("Sliced String:"+str.stringSlice(start,end)); + break; + case 6: + System.out.println("String:"+str.splitString()); + break; + case 7: + str.maxRepeat(); + break; + case 8: + System.out.print("Sorted String:"+str.sortString()); + break; + case 9: + System.out.print("Enter shift no: "); + int n = obj.nextInt(); + System.out.print("String:"+str.stringShift(n)); + break; + case 10: + System.out.print("Reverse String:"+ str.reverseString()); + break; + case 11: + System.out.println("Exiting..."); + break; + default: + System.out.println("Incorrect option!"); + } + } + obj.close(); + } +} diff --git a/StringOp.class b/StringOp.class new file mode 100644 index 0000000000000000000000000000000000000000..81c25877b8761e19a36313e34caf8c8f693509b9 GIT binary patch literal 3675 zcmcguTXS1i75=t#q$A7nC5n$-#h0pS;@FliZE)0JCvFo#5(mi+Q4-g6T5>F%#ENAd zAsr`iY0{fZ3pAya2N+;zCuJrtyo3Rpx*h)jc!n2VnBj#tUJKKy`Sw1td=t#@!h^T= z*?aA^zxAzet?fU2xwa1ABt8hj1FsG(1RwkY%{R?k=1|@&+!&giy=i3}0so0yA?J(< zczb%U=m_jEN;{=o;YI*K0R*8VB>gl97(K}?Pp;8u@0B__WzLrgF|4XJyAM zIAwwET8Q@E5{5vhbk-$syvC8eCwliT>4*yKR|G6Nx%|+nQpsFO=E_bGkHaeic`}4U zI4n@_*oir_qznYKp5B>6J&vG9M{fvyhzT@qxse_ivYE~9BG^sUXzvRW{eVP2C~%|( z`a}(|^1i1+cv|wRm2)p!65m&39)|^dJu?ZJw>X~BaXf^tVq|Cjm&%T{Kv4D~p&2d} zIeX{=Wg(MknG2&qoWMyPV<9{%rQ!0j(?&oq$`koQ0H>&i@xm=LpUXx|6r#eD2;pn^ zxu?b}u< zVU{g{mYy2-25^ztny{Vd1!6B`OZI{lz$Jm;)^`|QM8eQ8C6n~Lj3H4AVGu81M#t3< zUX)pIt8z<9l(Sa0OHPtYY5GSW=}@4hhPEbhtT4=W`j} z;FF0^tHpe-TEd}Rc`NX(BXhayREoyL@I>8$dFP^4v`j|_-Fs%nNtcXl^Ljm-EA##( zE~o9qQpP%ylQA`VQGUK9up&%{95x-S=BGuAt?YXzrWlbPbOI z^q@XsYv@p4(w|59lSK^h;X@tTI37klGU^7=M%P&`y5Ro83v_PSpW^Z9RXmZb;!C+# z9-J6hk89qz&+r-A0}KxszTvpv@Ha<4!ejjk(t%k2C+PNIDqNR(h)}=bUqe5TTK0*D z8-H|d>Njm-pI}Jf*HxrP6d!? zu{%Mg2MpbvFZ&7jPkjSK`WqZ`-HdLjp_?iIhNy$5i1TUAj$(vp6Z{^>aZK>xe4Z;( zAyH@>XqR+039+5lt_rP$e-rbSAnuY?FHfCqCxIRA#VsEr(BAPYga{@4+zLh?^~nuy z`wC9WNyiG#Y$~>bc8xF~E$Pao`2Z6q{{w8n7!&_26MqWN;55z3B+|l_lx?&x}6!V8}622*^UG@k{`{BmlWLnZY$R1>O z02NSAXbpVZ!o>H} zUYpzS*wn5LYS$)JPy2gwR5lH1JmQP^*5iJ!tWLxK0KE~Pp%2FcMxZ(RA&h<_FlcD3 z1v!apMqq4NXQ}>~!F3wi8m{b$ZH#XTaElVUjYiyIZ&_ls-l2?MVV&N^DDGhjuQDgE zvA4a>h~HpP_juxMEaM#&?=jgKSwE`#u#Uf7X+WRjzy^Czpt>&WTlLItc1yBT-eiZ` zWPK4xY@51bzsIynP|R(K)%?6vjlq4(T2=PnrJC+Dn)jHKAF?;T&kLOD1^sl-W{u{m zmv8Oz;=YI<(8G@@^+nox80BsL_Ok=u;puy7d`*pSsBu}1-&Nx~YWzOl<%uAz?-Rw3 G5cxOUBn>qH literal 0 HcmV?d00001 From 22efa134c28c352cb726cc3059418c7c486ccccf Mon Sep 17 00:00:00 2001 From: Priyansh Singh Date: Wed, 8 Oct 2025 20:51:43 +0530 Subject: [PATCH 2/5] Delete MyString.java --- MyString.java | 222 -------------------------------------------------- 1 file changed, 222 deletions(-) delete mode 100644 MyString.java diff --git a/MyString.java b/MyString.java deleted file mode 100644 index 4881d91..0000000 --- a/MyString.java +++ /dev/null @@ -1,222 +0,0 @@ -import java.util.*; - -class StringOp{ - String currentString = new String(""); - StringOp(String s){ - this.currentString=s; - } - //Function to append the String - public String append(String given_String) { - if (currentString.length()>0) //adding spaces between words - currentString+=' '; - currentString+=given_String; - return currentString; - } - - //function to count the words in the string - public int countWords() { - String temp_st = new String(""); //temporary string to store the word - int word_count=0; - for (char ch : currentString.toCharArray()) { - if (ch == ' ' || ch==',') { - if (temp_st.length() > 0) { - word_count++; //adding the word count - temp_st=""; //making the string empty - } - } else { - temp_st+=ch; //adding character in string - } - } - if (temp_st.length() > 0) - word_count++; //adding last word count - return word_count; - } - - //function to reverse the string - public String reverseString() { - char[] char_array = currentString.toCharArray(); // Convert to char array - char[] reversed = new char[char_array.length]; // Create array for reversed characters - - for (int i = char_array.length - 1, j = 0; i >= 0; i--, j++) { - reversed[j] = char_array[i]; - } - - currentString = new String(reversed); //converted the char[] in string - return currentString; - } - - //function to replace the character in the string - public String replaceChar(char a,char b){ - String temp_string=new String(""); //making temp empty string for storing the char - for (char ch: currentString.toCharArray()){ - if (ch==a){ - temp_string+=b; - } - else{ - temp_string+=ch; - } - } - currentString=temp_string; - return currentString; - } - //function to delete the substring - public String stringSlice(int start,int end){ - if (start < 0 || end > currentString.length() || start > end) { //valid checks befor slicing - return "0"; - } - currentString=currentString.substring(0,start)+currentString.substring(end); - return currentString; - } - //function to split string in array - public List splitString(){ - List word_List = new ArrayList<>(); - String st = new String(""); - for (char ch : currentString.toCharArray()) { - if (ch == ' ') { - if (st.length() > 0) { - word_List.add(st); - st=""; - } - } else { - st+=ch; - } - } - if (st.length() > 0) - word_List.add(st); - return word_List; - } - //function to check the string is pallindrome or not - public boolean isPalindrome() { - char[] st=currentString.toLowerCase().toCharArray(); // Convert to char array - int left=0; - int right=st.length-1; - while(left<=right){ - if (st[left]!=st[right]){ - return false; - } - left++; - right--; - } - return true; - } - - //function to shift the char of the string - public String stringShift(int n){ - if (n<0) - return currentString ; - int len = currentString.length(); - if (len == 0) return currentString; - n = n % len; - String s = currentString; - String shifted = s.substring(len - n) + s.substring(0, len - n); - currentString = new String(shifted); - return currentString; - - } - - //function to find the repeating char in string - public void maxRepeat() { - String temp = currentString.toLowerCase(); - int[] freq = new int[256]; //intitalizing the frequency array - for (char c : temp.toCharArray()) { - freq[c]++; - } - - char maxChar = ' '; - int maxCount = 0; - for (char c : temp.toCharArray()) { - if (c!=' '){ - if (freq[c] > maxCount) { - maxCount = freq[c]; - maxChar = c; - } - } - } - - System.out.println("Character with maximum occurrence: " + maxChar + " -> " + maxCount); - } - - //function to sort the string - public String sortString() { - char[] sstring = currentString.toLowerCase().toCharArray(); - Arrays.sort(sstring); - currentString = new String(sstring); - return currentString; - } -} - -class MyString{ - public static void main(String[] args) { - Scanner obj = new Scanner(System.in); - int option = 0; - - System.out.print("Enter the initial string: "); - StringOp str = new StringOp(obj.nextLine()); - while (option != 11) { - System.out.println("\nSelect the Operation:"); - System.out.println("1. Append the string"); - System.out.println("2. Count the words"); - System.out.println("3. Replace the character"); - System.out.println("4. Check Palindrome"); - System.out.println("5. Slicing the string"); - System.out.println("6. Split the String"); - System.out.println("7. Maximum Repeating Character"); - System.out.println("8. Sort the String"); - System.out.println("9. Shift character in string"); - System.out.println("10. Reverse the string"); - System.out.println("11. Exit"); - System.out.print("Enter your choice: "); - option = obj.nextInt(); - obj.nextLine(); - - switch (option) { - case 1: - System.out.print("Enter the string to append: "); - System.out.println("Appended String: " + str.append(obj.nextLine())); - break; - case 2: - System.out.println("Word count: " + str.countWords()); - break; - case 3: - System.out.println("Enter the character to replace :"); - char a=obj.next().charAt(0); - System.out.println("Enter the character to replace with:"); - char b=obj.next().charAt(0); - System.out.println("String:"+str.replaceChar(a,b)); - break; - case 4: - System.out.println(str.isPalindrome()); - break; - case 5: - System.out.println("Enter the start and end (s,e) to delete:"); - int start=obj.nextInt(); - int end=obj.nextInt(); - System.out.println("Sliced String:"+str.stringSlice(start,end)); - break; - case 6: - System.out.println("String:"+str.splitString()); - break; - case 7: - str.maxRepeat(); - break; - case 8: - System.out.print("Sorted String:"+str.sortString()); - break; - case 9: - System.out.print("Enter shift no: "); - int n = obj.nextInt(); - System.out.print("String:"+str.stringShift(n)); - break; - case 10: - System.out.print("Reverse String:"+ str.reverseString()); - break; - case 11: - System.out.println("Exiting..."); - break; - default: - System.out.println("Incorrect option!"); - } - } - obj.close(); - } -} From f3d5f455b86105fbde904164d6e62149c36d7f04 Mon Sep 17 00:00:00 2001 From: Priyansh Singh Date: Wed, 8 Oct 2025 20:51:56 +0530 Subject: [PATCH 3/5] Delete StringOp.class --- StringOp.class | Bin 3675 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 StringOp.class diff --git a/StringOp.class b/StringOp.class deleted file mode 100644 index 81c25877b8761e19a36313e34caf8c8f693509b9..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 3675 zcmcguTXS1i75=t#q$A7nC5n$-#h0pS;@FliZE)0JCvFo#5(mi+Q4-g6T5>F%#ENAd zAsr`iY0{fZ3pAya2N+;zCuJrtyo3Rpx*h)jc!n2VnBj#tUJKKy`Sw1td=t#@!h^T= z*?aA^zxAzet?fU2xwa1ABt8hj1FsG(1RwkY%{R?k=1|@&+!&giy=i3}0so0yA?J(< zczb%U=m_jEN;{=o;YI*K0R*8VB>gl97(K}?Pp;8u@0B__WzLrgF|4XJyAM zIAwwET8Q@E5{5vhbk-$syvC8eCwliT>4*yKR|G6Nx%|+nQpsFO=E_bGkHaeic`}4U zI4n@_*oir_qznYKp5B>6J&vG9M{fvyhzT@qxse_ivYE~9BG^sUXzvRW{eVP2C~%|( z`a}(|^1i1+cv|wRm2)p!65m&39)|^dJu?ZJw>X~BaXf^tVq|Cjm&%T{Kv4D~p&2d} zIeX{=Wg(MknG2&qoWMyPV<9{%rQ!0j(?&oq$`koQ0H>&i@xm=LpUXx|6r#eD2;pn^ zxu?b}u< zVU{g{mYy2-25^ztny{Vd1!6B`OZI{lz$Jm;)^`|QM8eQ8C6n~Lj3H4AVGu81M#t3< zUX)pIt8z<9l(Sa0OHPtYY5GSW=}@4hhPEbhtT4=W`j} z;FF0^tHpe-TEd}Rc`NX(BXhayREoyL@I>8$dFP^4v`j|_-Fs%nNtcXl^Ljm-EA##( zE~o9qQpP%ylQA`VQGUK9up&%{95x-S=BGuAt?YXzrWlbPbOI z^q@XsYv@p4(w|59lSK^h;X@tTI37klGU^7=M%P&`y5Ro83v_PSpW^Z9RXmZb;!C+# z9-J6hk89qz&+r-A0}KxszTvpv@Ha<4!ejjk(t%k2C+PNIDqNR(h)}=bUqe5TTK0*D z8-H|d>Njm-pI}Jf*HxrP6d!? zu{%Mg2MpbvFZ&7jPkjSK`WqZ`-HdLjp_?iIhNy$5i1TUAj$(vp6Z{^>aZK>xe4Z;( zAyH@>XqR+039+5lt_rP$e-rbSAnuY?FHfCqCxIRA#VsEr(BAPYga{@4+zLh?^~nuy z`wC9WNyiG#Y$~>bc8xF~E$Pao`2Z6q{{w8n7!&_26MqWN;55z3B+|l_lx?&x}6!V8}622*^UG@k{`{BmlWLnZY$R1>O z02NSAXbpVZ!o>H} zUYpzS*wn5LYS$)JPy2gwR5lH1JmQP^*5iJ!tWLxK0KE~Pp%2FcMxZ(RA&h<_FlcD3 z1v!apMqq4NXQ}>~!F3wi8m{b$ZH#XTaElVUjYiyIZ&_ls-l2?MVV&N^DDGhjuQDgE zvA4a>h~HpP_juxMEaM#&?=jgKSwE`#u#Uf7X+WRjzy^Czpt>&WTlLItc1yBT-eiZ` zWPK4xY@51bzsIynP|R(K)%?6vjlq4(T2=PnrJC+Dn)jHKAF?;T&kLOD1^sl-W{u{m zmv8Oz;=YI<(8G@@^+nox80BsL_Ok=u;puy7d`*pSsBu}1-&Nx~YWzOl<%uAz?-Rw3 G5cxOUBn>qH From 45e01410fd615877f160cef582299b5c18ca384f Mon Sep 17 00:00:00 2001 From: Priyansh Singh Date: Wed, 8 Oct 2025 20:52:10 +0530 Subject: [PATCH 4/5] Delete MyString.class --- MyString.class | Bin 2703 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 MyString.class diff --git a/MyString.class b/MyString.class deleted file mode 100644 index b2aff31ef5d5d5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jC zfu0%Y*@12k^xQzt5A=dS#|f1{JLWO+iu&D@IQ}Hz3TjB&NX{ckk=#SFgXA@mH%Q(k zIZW~s$#0xwqO63bB039y&!%fSox7KV5M<%+)7bEQIuhWDiXv9ER`SiIuK#_(-AT0@+1tJG8*s+Ef9DU?1TE2~gCM9MCd-X@hVl=ibvZ%|*W z+*B(UaYdo@6n%R&NoS$-AX{9^X_fBc;}-9DJw?Bsr#Z}<=C5d{^LFaS4vfMBsKrAx z_=nMeotT72F%6HA#p8%$7dr6-E!&gyVn0P4E1(BY!@)Dyh~3zNXDQxu*ox;V+6xrn zMSO`p_#Q9gXS{-6@G5>oKT3Fwh`m=-W1kp>*Tq=u7Y#TdCgTk;1#gP!cuUO0+hRW6 z5gm9}bmBdc#QS174vJMcBv#|F(D0#1<0H|Hk3|nY6%IZVefV5#!WUvQz7#j$D{%|H z7PsRYu?^pf?f6dY!VjW=A8`j&I~K>3&>%sQ5D|Z2Pu<8^XnZIXstbq1MC3cY=G=w5 XNy|i)dq}oZYk)AF9;DKC;)H(yitX1w From a8244df5f7396def2b726b8672123a11fb17da81 Mon Sep 17 00:00:00 2001 From: Priyansh Singh Date: Wed, 8 Oct 2025 20:53:11 +0530 Subject: [PATCH 5/5] Changes made after code review by Priyansh --- MyString.class | Bin 0 -> 3172 bytes MyString.java | 223 +++++++++++++++++++++++++++++++++++++++++++++++++ StringOp.class | Bin 0 -> 3342 bytes 3 files changed, 223 insertions(+) create mode 100644 MyString.class create mode 100644 MyString.java create mode 100644 StringOp.class diff --git a/MyString.class b/MyString.class new file mode 100644 index 0000000000000000000000000000000000000000..26c955cf35f7733d6ced6320ae5512ee5898f1f7 GIT binary patch literal 3172 zcmai0Yit}>75;9#_KY`^Hr~c=+B#-j(sZ3B>!xj-#BONQC8j2J9OB?K39rd|8c)1C zv&_yWHg5_o&+-gSAJDY4soRv$BrWT(p%D}WY6U7(yo3M=sp3}!zxV@^!*^z8v$kx3 zrF-xA+dss4q3+>>hwWUT&~&@w z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S%ug5xfiq1C( zWO{a^d>#uw*Amb}LXssRN&b#4{CH-0^Y(IT*6tk1TU%NI|(&fs-*9=}!>@f-Cz-cWDgx9V^Boq7|0P;cRn>Yw09=PF zX3?oZBSkv?gI89yY%#i8np!$rl1aWvPlQQ%k^uti*vy|IisFCF9^QhuSxaPlKLt0z_ literal 0 HcmV?d00001 diff --git a/MyString.java b/MyString.java new file mode 100644 index 0000000..83876c5 --- /dev/null +++ b/MyString.java @@ -0,0 +1,223 @@ +import java.util.*; + +class StringOp{ + String currentString = new String(""); + StringOp(String s){ + this.currentString=s; + } + //Function to append the String + public String append(String given_String) { + if (currentString.length()>0) //adding spaces between words + currentString+=' '; + currentString+=given_String; + return currentString; + } + + //function to count the words in the string + public int countWords() { + String temp_st = new String(""); //temporary string to store the word + int word_count=0; + for (char ch : currentString.toCharArray()) { + if (ch == ' ' || ch==',') { + if (temp_st.length() > 0) { + word_count++; //adding the word count + temp_st=""; //making the string empty + } + } else { + temp_st+=ch; //adding character in string + } + } + if (temp_st.length() > 0) + word_count++; //adding last word count + return word_count; + } + + //function to reverse the string + public String reverseString() { + char[] char_array = currentString.toCharArray(); // Convert to char array + char[] reversed = new char[char_array.length]; // Create array for reversed characters + + for (int i = char_array.length - 1, j = 0; i >= 0; i--, j++) { + reversed[j] = char_array[i]; + } + + currentString = new String(reversed); //converted the char[] in string + return currentString; + } + + //function to replace the character in the string + public String replaceChar(char a,char b){ + String temp_string=new String(""); //making temp empty string for storing the char + for (char ch: currentString.toCharArray()){ + if (ch==a){ + temp_string+=b; + } + else{ + temp_string+=ch; + } + } + currentString=temp_string; + return currentString; + } + //function to delete the substring + public String stringSlice(int start,int len){ + if (start < 0 || start+len > currentString.length() || start>currentString.length()) { //valid checks befor slicing + return currentString; + } + currentString=currentString.substring(0,start)+currentString.substring(start+len); + return currentString; + } + //function to split string in array + public List splitString(){ + List word_List = new ArrayList<>(); + String st = new String(""); + for (char ch : currentString.toCharArray()) { + if (ch == ' ') { + if (st.length() > 0) { + word_List.add(st); + st=""; + } + } else { + st+=ch; + } + } + if (st.length() > 0) + word_List.add(st); + return word_List; + } + //function to check the string is pallindrome or not + public boolean isPalindrome() { + char[] st=currentString.toLowerCase().toCharArray(); // Convert to char array + int left=0; + int right=st.length-1; + while(left<=right){ + if (st[left]!=st[right]){ + return false; + } + left++; + right--; + } + return true; + } + + //function to shift the char of the string + public String stringShift(int n){ + if (n<0) + return currentString ; + int len = currentString.length(); + if (len == 0) return currentString; + n = n % len; + String s = currentString; + String shifted = s.substring(len - n) + s.substring(0, len - n); + currentString = new String(shifted); + return currentString; + + } + + //function to find the repeating char in string + public void maxRepeat() { + String temp = currentString.toLowerCase(); + int[] freq = new int[256]; //intitalizing the frequency array + for (char c : temp.toCharArray()) { + freq[c]++; + } + + char maxChar = ' '; + int maxCount = 0; + for (char c : temp.toCharArray()) { + if (c!=' '){ + if (freq[c] > maxCount) { + maxCount = freq[c]; + maxChar = c; + } + } + } + + System.out.println("Character with maximum occurrence: " + maxChar + " -> " + maxCount); + } + + //function to sort the string + public String sortString() { + char[] sstring = currentString.toLowerCase().toCharArray(); + Arrays.sort(sstring); + currentString = new String(sstring); + return currentString; + } +} + +class MyString{ + public static void main(String[] args) { + Scanner obj = new Scanner(System.in); + int option = 0; + + System.out.print("Enter the initial string: "); + StringOp str = new StringOp(obj.nextLine()); + while (option != 11) { + System.out.println("\nSelect the Operation:"); + System.out.println("1. Append the string"); + System.out.println("2. Count the words"); + System.out.println("3. Replace the character"); + System.out.println("4. Check Palindrome"); + System.out.println("5. Slicing the string"); + System.out.println("6. Split the String"); + System.out.println("7. Maximum Repeating Character"); + System.out.println("8. Sort the String"); + System.out.println("9. Shift character in string"); + System.out.println("10. Reverse the string"); + System.out.println("11. Exit"); + System.out.println("currentString:"+str.currentString); + System.out.print("Enter your choice: "); + option = obj.nextInt(); + obj.nextLine(); + + switch (option) { + case 1: + System.out.print("Enter the string to append: "); + System.out.println("Appended String: " + str.append(obj.nextLine())); + break; + case 2: + System.out.println("Word count: " + str.countWords()); + break; + case 3: + System.out.println("Enter the character to replace :"); + char a=obj.next().charAt(0); + System.out.println("Enter the character to replace with:"); + char b=obj.next().charAt(0); + System.out.println("String:"+str.replaceChar(a,b)); + break; + case 4: + System.out.println(str.isPalindrome()); + break; + case 5: + System.out.println("Enter the start and length (s,l) to delete:"); + int start=obj.nextInt(); + int len=obj.nextInt(); + System.out.println("Sliced String:"+str.stringSlice(start,len)); + break; + case 6: + System.out.println("String:"+str.splitString()); + break; + case 7: + str.maxRepeat(); + break; + case 8: + System.out.print("Sorted String:"+str.sortString()); + break; + case 9: + System.out.print("Enter shift no: "); + int n = obj.nextInt(); + System.out.print("String:"+str.stringShift(n)); + break; + case 10: + System.out.print("Reverse String:"+ str.reverseString()); + break; + case 11: + System.out.println("Exiting..."); + break; + default: + System.out.println("Incorrect option!"); + } + } + obj.close(); + } +} diff --git a/StringOp.class b/StringOp.class new file mode 100644 index 0000000000000000000000000000000000000000..3116c2e34bc2854fe0f27508ff4e14a7b619797a GIT binary patch literal 3342 zcmaJ@-*X#R89i58X(d^)9VJ`Ww(O{(aU{#KOX`T!zi6uv;zY93IUp zN-MiA11(?%cmVpy07El@nY@&l!hi#A$M5`jrGEp%3$KOg)SSD!{uR57$1CaH?|%1u z=R4<<{`&dWHh^(_GXfv{DwHS!2nw_>>#O=uS+6b*O)o4PMOz>^W>!smLcpI)&8i3; z3YxL&W_2-yhyWr`5tVsP2x!UtekM0)G&LJW8`@Qzj3S0p0wH%}x+ZX<*sRx$s_m`_ z#Eu@9>9r`HLI*LGjq0MkIz9 zZ;3&mM<(kPxOB{sqbE{Fmn76g6wlzSK#OhVmh}2d^}4<;pd?fCIeEvk@{V%?=a0D~ z_XR1>OLCI}f#iHHH7hUak0Ol$fpDX_&~REI@Kkbg@(U6S%J3oCo#P@@d|BX>)3&B< zmWLe3d9z_h@ErUt7{)~v*(kn(O9HL?aWaIR&`YH!`tB-dG<8Qp9f@KTV-6pAYt5+V z^oAjDI(Z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