From 80e84e433801e21445a96fc58ae04e63b2054c2e Mon Sep 17 00:00:00 2001 From: masumrazait Date: Sun, 1 Mar 2026 00:53:58 +0530 Subject: [PATCH 1/3] added new code with Logic explanation --- .../CharacterCount.java | 25 +++++++++++++++ .../CharacterCounts.java | 30 ++++++++++++++++++ .../PrimeChecker.java | 30 ++++++++++++++++++ .../SecondHigherNumInArray.java | 28 ++++++++++++++++ .../VowelLetterCount.java | 30 ++++++++++++++++++ .../WhiteSpaceCount.java | 25 +++++++++++++++ .../WordCountExample.java | 29 +++++++++++++++++ .../interviewPractice2026/pom.properties | 2 +- .../CharacterCount.class | Bin 0 -> 1279 bytes .../CharacterCounts.class | Bin 0 -> 1441 bytes .../PrimeChecker.class | Bin 0 -> 1185 bytes .../SecondHigherNumInArray.class | Bin 0 -> 1165 bytes .../VowelLetterCount.class | Bin 0 -> 1278 bytes .../WhiteSpaceCount.class | Bin 0 -> 834 bytes .../WordCountExample.class | Bin 0 -> 1965 bytes 15 files changed, 198 insertions(+), 1 deletion(-) create mode 100644 src/test/java/codeWithLogicExplanation/CharacterCount.java create mode 100644 src/test/java/codeWithLogicExplanation/CharacterCounts.java create mode 100644 src/test/java/codeWithLogicExplanation/PrimeChecker.java create mode 100644 src/test/java/codeWithLogicExplanation/SecondHigherNumInArray.java create mode 100644 src/test/java/codeWithLogicExplanation/VowelLetterCount.java create mode 100644 src/test/java/codeWithLogicExplanation/WhiteSpaceCount.java create mode 100644 src/test/java/codeWithLogicExplanation/WordCountExample.java create mode 100644 target/test-classes/codeWithLogicExplanation/CharacterCount.class create mode 100644 target/test-classes/codeWithLogicExplanation/CharacterCounts.class create mode 100644 target/test-classes/codeWithLogicExplanation/PrimeChecker.class create mode 100644 target/test-classes/codeWithLogicExplanation/SecondHigherNumInArray.class create mode 100644 target/test-classes/codeWithLogicExplanation/VowelLetterCount.class create mode 100644 target/test-classes/codeWithLogicExplanation/WhiteSpaceCount.class create mode 100644 target/test-classes/codeWithLogicExplanation/WordCountExample.class diff --git a/src/test/java/codeWithLogicExplanation/CharacterCount.java b/src/test/java/codeWithLogicExplanation/CharacterCount.java new file mode 100644 index 0000000..2422ce1 --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/CharacterCount.java @@ -0,0 +1,25 @@ +package codeWithLogicExplanation; + +import java.util.HashMap; + +public class CharacterCount { + + public static void main(String[] args) { + + // Input string + String str = "masum"; + + // HashMap to store character as key and its count as value + HashMap map = new HashMap<>(); + + // Loop through each character in the string + for (char c : str.toCharArray()) { + // getOrDefault(c, 0) returns the current count if present, otherwise 0 + // Then we add 1 to update the count + map.put(c, map.getOrDefault(c, 0) + 1); + } + + // Print the final map showing character counts + System.out.println(map); + } +} \ No newline at end of file diff --git a/src/test/java/codeWithLogicExplanation/CharacterCounts.java b/src/test/java/codeWithLogicExplanation/CharacterCounts.java new file mode 100644 index 0000000..0946395 --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/CharacterCounts.java @@ -0,0 +1,30 @@ +package codeWithLogicExplanation; + +import java.util.HashMap; + +public class CharacterCounts { + public static void main(String[] args) { + + // Input string + String str = "masum"; + + // HashMap to store character as key and its frequency as value + HashMap map = new HashMap<>(); + + // Loop through each character in the string + for (char c : str.toCharArray()) { + + // Check if the character already exists in the map + if (map.containsKey(c)) { + // If yes, increment its count + map.put(c, map.get(c) + 1); + } else { + // If not, add it with initial count = 1 + map.put(c, 1); + } + } + + // Print the final map showing character counts + System.out.println(map); + } +} \ No newline at end of file diff --git a/src/test/java/codeWithLogicExplanation/PrimeChecker.java b/src/test/java/codeWithLogicExplanation/PrimeChecker.java new file mode 100644 index 0000000..61f4161 --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/PrimeChecker.java @@ -0,0 +1,30 @@ +package codeWithLogicExplanation; + +public class PrimeChecker { + + public static void main(String[] args) { + // Loop through numbers from 1 to 100 + for (int num = 1; num <= 100; num++) { + // Call isPrime() and print result using ternary operator + System.out.println(num + " is " + (isPrime(num) ? "Prime" : "Not Prime")); + } + } + + // Method to check if a number is prime + private static boolean isPrime(int num) { + + // Prime numbers are greater than 1 + if (num <= 1) + return false; + + // Check divisibility from 2 up to sqrt(num) + // If divisible by any number in this range, it's not prime + for (int i = 2; i <= Math.sqrt(num); i++) { + if (num % i == 0) + return false; + } + + // If no divisors found, it's prime + return true; + } +} \ No newline at end of file diff --git a/src/test/java/codeWithLogicExplanation/SecondHigherNumInArray.java b/src/test/java/codeWithLogicExplanation/SecondHigherNumInArray.java new file mode 100644 index 0000000..c1f5407 --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/SecondHigherNumInArray.java @@ -0,0 +1,28 @@ +package codeWithLogicExplanation; + +public class SecondHigherNumInArray { + + public static void main(String[] args) { + + int arr[] = { 112, 34, 553, 35, 23, 678, 876, 366, 53, 757, 3425, 4444 }; + + int first = Integer.MIN_VALUE; // highest number + int second = Integer.MIN_VALUE; // second highest number + + // Loop through each number in the array + for (int num : arr) { + if (num > first) { + // If current number is greater than first, + // then update second as old first, and first as current number + second = first; + first = num; + } else if (num > second && num != first) { + // If current number is greater than second but not equal to first, + // update second + second = num; + } + } + + System.out.println("Second highest number is : " + second); + } +} \ No newline at end of file diff --git a/src/test/java/codeWithLogicExplanation/VowelLetterCount.java b/src/test/java/codeWithLogicExplanation/VowelLetterCount.java new file mode 100644 index 0000000..cfca4ba --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/VowelLetterCount.java @@ -0,0 +1,30 @@ +package codeWithLogicExplanation; + +public class VowelLetterCount { + + public static void main(String[] args) { + + // Input string + String input = "rajuiUmbrela"; + + // String containing all vowels (both uppercase and lowercase) + String vowel = "AEIOUaeiou"; + + // Counter to keep track of vowels + int count = 0; + + // Loop through each character of the input string + for (char c : input.toCharArray()) { + + // Check if the character exists in the vowel string + // indexOf(c) returns -1 if the character is not found + if (vowel.indexOf(c) != -1) { + count++; // Increase count if vowel found + System.out.print(c+" "); // Print the vowel character + } + } + + // Print total number of vowels found + System.out.println("\ntotal number of vowels found: "+count); + } +} \ No newline at end of file diff --git a/src/test/java/codeWithLogicExplanation/WhiteSpaceCount.java b/src/test/java/codeWithLogicExplanation/WhiteSpaceCount.java new file mode 100644 index 0000000..39fa5aa --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/WhiteSpaceCount.java @@ -0,0 +1,25 @@ +package codeWithLogicExplanation; + +public class WhiteSpaceCount { + + public static void main(String[] args) { + + // Input string with spaces + String input = "India is a big country"; + + // Counter to keep track of spaces + int count = 0; + + // Loop through each character in the string + for (int i = 0; i <= input.length() - 1; i++) { + + // Check if the current character is a space + if (input.charAt(i) == ' ') { + count++; // Increase count if space found + } + } + + // Print total number of spaces + System.out.println(count); + } +} \ No newline at end of file diff --git a/src/test/java/codeWithLogicExplanation/WordCountExample.java b/src/test/java/codeWithLogicExplanation/WordCountExample.java new file mode 100644 index 0000000..207a2ba --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/WordCountExample.java @@ -0,0 +1,29 @@ +package codeWithLogicExplanation; + +import java.util.HashMap; + +public class WordCountExample { + + public static void main(String[] args) { + + // Input sentence + String sentence = "Interview with aditya CGO Interview"; + + // Convert to lowercase and split by spaces + String[] words = sentence.toLowerCase().split(" "); + + // HashMap to store word as key and frequency as value + HashMap wordCount = new HashMap<>(); + + // Loop through each word + for (String word : words) { + // If word exists, increment count; otherwise start at 1 + wordCount.put(word, wordCount.getOrDefault(word, 0) + 1); + } + + // Print each word and its frequency + for (String word : wordCount.keySet()) { + System.out.println(word + ": " + wordCount.get(word)); + } + } +} \ No newline at end of file diff --git a/target/classes/META-INF/maven/com.interviewPractice2026/interviewPractice2026/pom.properties b/target/classes/META-INF/maven/com.interviewPractice2026/interviewPractice2026/pom.properties index 42fc131..a1b9187 100644 --- a/target/classes/META-INF/maven/com.interviewPractice2026/interviewPractice2026/pom.properties +++ b/target/classes/META-INF/maven/com.interviewPractice2026/interviewPractice2026/pom.properties @@ -1,5 +1,5 @@ #Generated by Maven Integration for Eclipse -#Sun Mar 01 00:25:16 IST 2026 +#Sun Mar 01 00:47:00 IST 2026 artifactId=interviewPractice2026 groupId=com.interviewPractice2026 m2e.projectLocation=D\:\\My_Project\\Testing_Project\\interviewPractice2026 diff --git a/target/test-classes/codeWithLogicExplanation/CharacterCount.class b/target/test-classes/codeWithLogicExplanation/CharacterCount.class new file mode 100644 index 0000000000000000000000000000000000000000..24a6c7d13ebc85da8db8548c70bdcc1d2a0e2af0 GIT binary patch literal 1279 zcma)6%Tg0T6g^EQGzo)1Vt9xk;DZDr@qvg0q8LD;K`608QEY7DkPId>sYwqddw;~0 zYh3`PRg`PD{(|2j-kt;q1q&DHp1zMh=iYldzy5wd0x*GPjwXhYy#3x-H)Szv7tH*^ z$4W_9LYlUfNEd}8^3rh9wrfcajiF;l?1}_M6cQ_2J4RkIG|!lpDN_u-Xe`H|rRlmL zd_W2$rAsL7&PWr$_}lTMPL%EGi5x}uxe zGg@oXF|9%}mTN&LgTE}QZkZ#@(CNjv(kvyGM76jqDnW!02%-x;9Np(?t6id_7uOhC zrL8(K=Qv`IK%=qEbP(4uz|qeTK0`ijmyR14WZ=7^`K#*#+CaMUfgRdt!h+`5x8Lm1H!MT|i&7;?p#H@1aaqJd0B8?b6qN?x=yURn=Q zY{qoNahIXRv}8{4_vV^Wa0wmv6r8W($^afa?-x@ZXHR?Q2Qz>qeKIaTvCuHHQ^LUGT}?cPxw{oD5;&zr>+cg zl|_ZpYOY2>kfvCkeram^d5!K>PINkZF>R&+hjn=A{*1qN0WZvr1k~z-sXrlk&5>p zqR(4=hZx$&ou3%q$EfzsJB_b@(pW@`_&*>2{)YSUeLPlFG$<+q9)$W|Xd^luR7n_f zw7)_(-k`^$I7+cZ1G7lc?!zjc;u(=_#S+Cnr<#W_h&1NOw?Gl9q?&J$d@sn-i>71r XfpaWzba4_bV;mXKJ7EN++LrwXIj1e} literal 0 HcmV?d00001 diff --git a/target/test-classes/codeWithLogicExplanation/CharacterCounts.class b/target/test-classes/codeWithLogicExplanation/CharacterCounts.class new file mode 100644 index 0000000000000000000000000000000000000000..8ac21a64cc88a87b566de03826a4eb67d8664783 GIT binary patch literal 1441 zcma)6%Tg0T6g^EQGzo)1AUs4=P%#NeR1gsm#SsJv55)qJg*M|D29uf8q(jNxpK$4l zwJrjs7UkNH5^qle2?Yxm(~tW+_ukX<=kJe00K<66QNs{3-S^g-Ew@r`+BT;@CB^0to2{ zqL!gCWjoelA-idLuf%4?Vu++%Q)E_!XRCWzsL3rm&yYy{FP?GAl@+$b&=%WBRdB6H z&vw$|@zpvsGX%3DU&wN_Ff{u%1!-rJvm(E>AaY?u5DKFW9USeaiYo=t(TR%;_0m^~$9gJX%IW`lBuSKNYUS~IqKb*(3nO7D446@nfReEJ;#HFTl} zODm^al6FRWFtLxiZ@xNAt5TB?^|b2cvyKM3g>V6lBq3)u1kDe!9cfDaL}Yy*tqc7{ zMAye^4@ZK55p54fXKhp)o*d{tKvxkxU(o9x%l8|<5ig=&dv}0j5qH=2(Bx~h^8K^M zqFOZg_2}1kj0_Ypp%7|N2owGqqM~#{*+>OOFo0IfB8qvm<2A`P>Gj&^_Nz#cAFz!l zFlY}Tji;EVI_mKjGk8XA=^<*)Vvcmr$wF0K(#?}DMUrV~N9Y3QSm0>ml#elvMc|0K VSdp?5sa_>LwpHCrQK0|; literal 0 HcmV?d00001 diff --git a/target/test-classes/codeWithLogicExplanation/PrimeChecker.class b/target/test-classes/codeWithLogicExplanation/PrimeChecker.class new file mode 100644 index 0000000000000000000000000000000000000000..8ea86f858d21878081ffb4b22e1a1e4e32509831 GIT binary patch literal 1185 zcma)6O-~b16g{t<;k9M>Do~(REC|vfP*g;*h{~5CDPU4lqppT_Y#+2Ubvh-wa$~|@ zP#11AVIdn`0MW!B;L1PZKOolori}z);pV<~@4N4ubMJjKKYoAx4qyuRIXn!*Su1Be z5>6py_=M(E2n?}}QXqpwKaON1i zv3Q0-Ss<_gyzpyK(ZtY}5~i_MEo~U~Lw%!YFa%RpRxf6BTS&hVRGfmSFpQ-BOH7i8 zO1dx^Lb0c*V^L|x7G^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wGm0AU~CQN-+9H&fh-=i|Z8F9?6b zkQy4XXH7f Z3>?r$bOf>^@Jtu{Tj^Ze4PtWP<{u5|{c!*Q literal 0 HcmV?d00001 diff --git a/target/test-classes/codeWithLogicExplanation/VowelLetterCount.class b/target/test-classes/codeWithLogicExplanation/VowelLetterCount.class new file mode 100644 index 0000000000000000000000000000000000000000..13b7b229c5a6f6a1e930931a025abc81e05f238a GIT binary patch literal 1278 zcma)5+foxj5IvLIhOh_*7DPazq9oknB_a|;A%aE&K_js!9;_i5!r*2%wQLaH`47t{ zpYk21h*DY5=fT3-ZZ}TL@RFe6%O;K_gLQ~R`?lglxo+vT|G6Wcb zA5A)f2r;zgq$L*X)ivR~g;6m&?^PN0>Z}c818zTsFVVg|zDt80gZ_d8)AE^E$4eo1xjY zGaKBQaU8x&`QnMyj5^e#qZfS)nzYJdC%>*-*+jMp{kX0nb{cPY%N11}H*k|gvg@Ro zaZFd*$tB|IQbxh6X$`j+y3Q6dTbE{8I4bL)jyMvOb(@=Yp|TqBOyYd$5e#5h$v>hZ z&ij=#V+<^&0`KU!i+gmByjBxdnPK#z6X!rqXr&cIO2-3?GlX6HSUiS~_=UVCFsb1Y zL%Uby>H2k~72#k_NfO3mhW?0ayWEUfUiZZ8_1Ly*%B|QsHDr0xqyI$Ff6CBH`u~IE z1ZH()6u#!+o76S|?o_Dd+AnAxq9LuCx~k|oQ0lv&$AfH1O$I5MrMEdC2Hz^VA_cqdl*GJLQ(&AOurZ|xu7jF{1{Cno7fleY8tsx~8QI{_KEhu; zcZ62u1|4XoRX+|O+d{i0TtX}TQHKu^K$vVL+Lnt(7yQ%14RowbY6s&X|9J2VQr(&n zOpOOdj6efdeV-89^RsWb_7ejuM&LVc?_(%B+CZ{_`wcwY3o;{UggzhrK8cA=Q9xe< z)1H4u(ep#m8}in$M=(T$Xe4Pw3?$Hr5p-dm_DeKM>*(`JNKwT^6VEW`VU#K2ITaBC x#|!%M5yE?9@sbexF^E^lQE3Yl+XMd*jci!Mq6UK=l8b4`1EWgF*A(Kzn?LbzBR~KE literal 0 HcmV?d00001 diff --git a/target/test-classes/codeWithLogicExplanation/WhiteSpaceCount.class b/target/test-classes/codeWithLogicExplanation/WhiteSpaceCount.class new file mode 100644 index 0000000000000000000000000000000000000000..d6bf3c4e68467637c65ee0892127ace71dbbb086 GIT binary patch literal 834 zcma)4U2hUW6g|T(EUa5gftIR8x3yY6YEk1G+Qbk|NY-kCp$|R{%Ve1fyJQ)ReeVx3 z#>8iRz{CfCfd9llQN6P?F{lqd%)K*nKh8OG=ll8BZvYD z133q2WEfUG8H%IXxG&tafT` zoqxr_Ra~RUNQ8kJCW<>bRB*$>_2ovVQzga@Tx?TTG@~x-3yLyoz94>zpadVcY}~{x z3%d-(M8R^{!ENj@SQA|_BBh#&eq$a7^j5`x$Yw~(aH0VVf4>O@6Zs6RLrXHObQSks zKjV{&DcId;7W?9<)N?BR@dFMtMQnp4(FX!jw4)J|wdm9&&&a3iUy%Kjgl)1q3@W%p z)>$NwU!hYDm$6DWy7)b1nB?~hdCz!c9DYQxQJJHVci$m%mSSfHt2E}=GzTAk{`ico ztvPlyh5?PSgDlx>f|91LHr7x=0cG0nl5Jo!!LKhcP(>}Nt)WgaEn*M*xI=<0n&tuR W43eYy8t1Sr6d7~0*t>L>!o6S6*s@gs literal 0 HcmV?d00001 diff --git a/target/test-classes/codeWithLogicExplanation/WordCountExample.class b/target/test-classes/codeWithLogicExplanation/WordCountExample.class new file mode 100644 index 0000000000000000000000000000000000000000..95d8ec2f21050b24e66ae095340bae4903a5d830 GIT binary patch literal 1965 zcma)7T~ixX7=8{(*bo*AfwZP7rp2}d3Q??B6RcWF8#ItA6{Pi}hhzy0o87qC@Nw&S z<#_4njCWpntrwxSGo4=d2l#Wu=WLde05du;=j?gEKc4r^^MC$&3g8-cG;|51OHSEX zF};m~Q!z_(yERMN(lZ@9v*NhrS*KxpbGx!yvkVPkf&NXoEi;sM#&TCo-u9H zyCD!7O)m?CXK65o5PEb(&@FJLVA{rFqq=6e_vD&o2*e9cNm|R&HPt&HhP@55E-+sB z-vQ<5tSU`g;Oyvw!ckyLo@?5bTzWZ*0fCWu+cVs4)7VMvFwK-Ko8F#G&E6@dUT|U< zL_)(*M}93cI?m#pK(FT%oE^iRm31aCG@3r?FN&mqNGV&d=y(;c2}J5O%VdeJjGh!v zpAxc$*98XrOd6hPW%9DVu^?+P45KH8i+DrB$f1DW1C>F=aCKb5WdUtlS`DMPt_m{W z9$_GsQ-(%$q%kI-R}8P{-ZIu@!(xcn+e2)%HrEz(KxsD`kW^e(bxdGVAZps)vWme6 z!@P3$rjECiyHKs+srTDDq4y3^vt{fp8FV~wSW7=+l5)Lx7w>7fF3@*W3NmzL!JbD= z_EUO}tI`Yt@^$9}It{#!4>S;x@goC=Tpb_cBO=E(cImydlR-*7n8loiTb*#&t9wRO z$8FqUHco@eiB^G3Cv%sG^9UG2R&yHW1`ASe6HRCzxWkdXLF0W(o-A!~5%{Z8!=^xN$!WMHaNu0@y>YdZ3G6+{HXKzB0T8@5tCbqJQ}87*E9}5xqS1;9Ex@Up;sUXGo#4C{ZFx z+As0`!gv$$_{&Y4UwDGy)qSKEudZgbr_B#R$C$&UmDjS|is{hagpc>J5Wm~R zXEfNvaufHP_^OGAN}P50_29WmCk&O&n18AtqCWohBf-f_^PJ;dL=q;><44{DLoQ=eM>D>ww9DjsX8gw5I*37 hjB4;S4EpCVgy08o=>S9M?%-%dGA3!ILESEF{|o2z>+k>o literal 0 HcmV?d00001 From 8d9f5852cf990f227f811595738567021c6e9ab4 Mon Sep 17 00:00:00 2001 From: masumrazait Date: Sun, 1 Mar 2026 01:02:24 +0530 Subject: [PATCH 2/3] added new code with Logic explanation --- .../ReveseSentnece.java | 31 ++++++++++++++++++ .../WhiteSpaceAndWordCount.java | 31 ++++++++++++++++++ .../WordCountExample.java | 10 ++++-- .../ReveseSentnece.class | Bin 0 -> 1448 bytes .../WhiteSpaceAndWordCount.class | Bin 0 -> 1229 bytes .../WordCountExample.class | Bin 1965 -> 2071 bytes 6 files changed, 70 insertions(+), 2 deletions(-) create mode 100644 src/test/java/codeWithLogicExplanation/ReveseSentnece.java create mode 100644 src/test/java/codeWithLogicExplanation/WhiteSpaceAndWordCount.java create mode 100644 target/test-classes/codeWithLogicExplanation/ReveseSentnece.class create mode 100644 target/test-classes/codeWithLogicExplanation/WhiteSpaceAndWordCount.class diff --git a/src/test/java/codeWithLogicExplanation/ReveseSentnece.java b/src/test/java/codeWithLogicExplanation/ReveseSentnece.java new file mode 100644 index 0000000..01d1f3f --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/ReveseSentnece.java @@ -0,0 +1,31 @@ +package codeWithLogicExplanation; + +public class ReveseSentnece { + public static void main(String[] args) { + // Input string where each word is reversed + String str = "ihled si latipac fo aidnI"; + + // Split the sentence into words using space as delimiter + String words[] = str.split(" "); + + // Variable to store the final reversed sentence + String revSen = ""; + + // Loop through each word + for (String word : words) { + String revWord = ""; // to store reversed word + int len = word.length(); + + // Reverse the current word character by character + for (int i = len - 1; i >= 0; i--) { + revWord = revWord + word.charAt(i); + } + + // Add the reversed word to the sentence + revSen = revSen + revWord + " "; + } + + // Print the final reversed sentence (trim removes extra space at the end) + System.out.println(revSen.trim()); + } +} \ No newline at end of file diff --git a/src/test/java/codeWithLogicExplanation/WhiteSpaceAndWordCount.java b/src/test/java/codeWithLogicExplanation/WhiteSpaceAndWordCount.java new file mode 100644 index 0000000..ad45de2 --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/WhiteSpaceAndWordCount.java @@ -0,0 +1,31 @@ +package codeWithLogicExplanation; + +public class WhiteSpaceAndWordCount { + public static void main(String[] args) { + String str = "hell aa ad ddsa ddd dd"; + + // Count spaces + int count = 0; + for (int i = 0; i <= str.length() - 1; i++) { + if (str.charAt(i) == ' ') { + count++; + } + } + System.out.println("Total white space count is : " + count); + + // Count words + int wordCount = 0; + for (int j = 0; j <= str.length() - 2; j++) { // avoid index out of bounds + // If current char is space AND next char is not space, + // it means a word has ended + if (str.charAt(j) == ' ' && str.charAt(j + 1) != ' ') { + wordCount++; + } + } + + // Add 1 to count the first word (since loop only counts transitions) + wordCount++; + + System.out.println("Total word Count is : " + wordCount); + } +} \ No newline at end of file diff --git a/src/test/java/codeWithLogicExplanation/WordCountExample.java b/src/test/java/codeWithLogicExplanation/WordCountExample.java index 207a2ba..2a97418 100644 --- a/src/test/java/codeWithLogicExplanation/WordCountExample.java +++ b/src/test/java/codeWithLogicExplanation/WordCountExample.java @@ -17,8 +17,14 @@ public static void main(String[] args) { // Loop through each word for (String word : words) { - // If word exists, increment count; otherwise start at 1 - wordCount.put(word, wordCount.getOrDefault(word, 0) + 1); + // Check if the word already exists in the map + if (wordCount.containsKey(word)) { + // If yes, increment its count + wordCount.put(word, wordCount.get(word) + 1); + } else { + // If not, add it with initial count = 1 + wordCount.put(word, 1); + } } // Print each word and its frequency diff --git a/target/test-classes/codeWithLogicExplanation/ReveseSentnece.class b/target/test-classes/codeWithLogicExplanation/ReveseSentnece.class new file mode 100644 index 0000000000000000000000000000000000000000..5c77e92589e24a81a6201d787b97a026a1c66d01 GIT binary patch literal 1448 zcma)5U3U{z6y3L(WG2I4OWFZbsirDz0xi)>qb7(#Ef`HdY@o<;`7li`$>3xrP9{~B zzPLnwg)jQTvpxhDti=!TSNKbe`%bF1G!H(^oqO&%XPq^EhLc=n5?kFLDe_s2KRy_(`zf~#h8aO48b=#h7=6Y_osMlyk4{LI?f5``;OO_TXzK(4o4o9y;3+%#zYQ_s_1zE`>@NuB~kF_EnL77Nj2I| zc$Il+`D$TJ`Chb8#2eH&-LCYT0%!AU$HN>jttgKb3vc0)fDr|w7y>i-<1VpnNuj?j zusn|0v1I;2w&^#`_jNP#iVR zMaRT7e5hkhU^?!=QF{yPs&;x;L3o@j%?Vqa$>}j&X5d~Fs#$)%l^o3E*Fo5%V=9#U zTpt3d2O?9x9p4fh365WtpDS>(9yyIKH=J&~3p#EHnDw9^Hsp0zEzI=MO}wZ=Vjkqc zJq9Lt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i6Qc0EwbMEkky8Aspg3>=5L|qNO8*Bb)|xh|f~(-ec(0aGar{+`njLveA@jam0}j zm2y*E7fx#EW~kc12Q9N;Sa~vV3O!;>uIoLGehqyL-W`*v`%9L&z%hU`G&f(g82rO! zIFpZ#7BV?2Wfe?gA)#TAAt0VB0bPd=XPws?7GLF7PZH-jRE&^P^eEN7aW^h7Nbx!y zNu)R~VN7%=33mt+9G5XEey}L@NaCu4T@&||*iaJJIi?X{a9eqrn8~Ge7?{;?gTeP7 zKO8rmiQ1xLF`M(C3v(Q4+!8;P?`&RtQy=V_C0B0xSgT^%RlgDmYJN2qSK5Nkk~dIq zqj?Kq8?DMr`4pXatTMmqcdeDawAqMl;wVF0eS=s~-NXroE%@TfJM?};ax$oFVCX&0 zRgK!XNDXa_+qhz5%EpXCHyK`+w%2LA0-fSYOF8L~Q9+Lve!9g7#eT{o2qJ?TJf-{! z``{r#H(ZW)s?SrF@e;R@1^oedf(5Ecqo|HCQ_5N(M{ l?NCYx!>z&6;48-v7^4l)SVA>i{~#J&EDlneB55To{{|OmoaF!j From 4f38f20d0abe59f31534d4b0e87181b9ac3b7fc5 Mon Sep 17 00:00:00 2001 From: masumrazait Date: Sun, 1 Mar 2026 01:05:41 +0530 Subject: [PATCH 3/3] added new code with Logic explanation --- .../ExpandString.java | 22 +++++++++++++++ .../StringCompresssed.java | 26 ++++++++++++++++++ .../WordDublicate.java | 26 ++++++++++++++++++ .../ExpandString.class | Bin 0 -> 1198 bytes .../StringCompresssed.class | Bin 0 -> 2083 bytes .../WordDublicate.class | Bin 0 -> 1378 bytes 6 files changed, 74 insertions(+) create mode 100644 src/test/java/codeWithLogicExplanation/ExpandString.java create mode 100644 src/test/java/codeWithLogicExplanation/StringCompresssed.java create mode 100644 src/test/java/codeWithLogicExplanation/WordDublicate.java create mode 100644 target/test-classes/codeWithLogicExplanation/ExpandString.class create mode 100644 target/test-classes/codeWithLogicExplanation/StringCompresssed.class create mode 100644 target/test-classes/codeWithLogicExplanation/WordDublicate.class diff --git a/src/test/java/codeWithLogicExplanation/ExpandString.java b/src/test/java/codeWithLogicExplanation/ExpandString.java new file mode 100644 index 0000000..3e950b1 --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/ExpandString.java @@ -0,0 +1,22 @@ +package codeWithLogicExplanation; + +public class ExpandString { + public static void main(String[] args) { + String str = "a2b3c4"; // input string with characters followed by numbers + String result = ""; // final expanded string + + // Loop through the string in steps of 2 (character + digit) + for (int i = 0; i < str.length(); i += 2) { + char ch = str.charAt(i); // the character + int count = Character.getNumericValue(str.charAt(i + 1)); // the number after character + + // Repeat the character 'count' times + for (int j = 1; j <= count; j++) { + result = result + ch; + } + } + + // Print the expanded string + System.out.println(result); + } +} \ No newline at end of file diff --git a/src/test/java/codeWithLogicExplanation/StringCompresssed.java b/src/test/java/codeWithLogicExplanation/StringCompresssed.java new file mode 100644 index 0000000..8e7334c --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/StringCompresssed.java @@ -0,0 +1,26 @@ +package codeWithLogicExplanation; + +import java.util.LinkedHashMap; +import java.util.Map; + +public class StringCompresssed { + public static void main(String[] args) { + String str = "aaaaaaggggg"; // input string + String result = ""; + + // LinkedHashMap preserves insertion order + Map charc = new LinkedHashMap<>(); + + // Count frequency of each character + for (char c : str.toCharArray()) { + charc.put(c, charc.getOrDefault(c, 0) + 1); + } + + // Build compressed string + for (Map.Entry entry : charc.entrySet()) { + result = result + entry.getKey() + entry.getValue(); + } + + System.out.println(result); + } +} \ No newline at end of file diff --git a/src/test/java/codeWithLogicExplanation/WordDublicate.java b/src/test/java/codeWithLogicExplanation/WordDublicate.java new file mode 100644 index 0000000..251b2f6 --- /dev/null +++ b/src/test/java/codeWithLogicExplanation/WordDublicate.java @@ -0,0 +1,26 @@ +package codeWithLogicExplanation; + +import java.util.HashSet; +import java.util.Set; + +public class WordDublicate { + public static void main(String[] args) { + String Str = "hello ram delhi patna bihar delhi patna bihar"; + + // Split the sentence into words + String[] words = Str.split(" "); + + // HashSet to store unique words + Set uniq = new HashSet<>(); + + // Add each word to the set + for (String word : words) { + uniq.add(word.trim()); // trim removes any accidental spaces + } + + // Print unique words + for (String word : uniq) { + System.out.println(word); + } + } +} \ No newline at end of file diff --git a/target/test-classes/codeWithLogicExplanation/ExpandString.class b/target/test-classes/codeWithLogicExplanation/ExpandString.class new file mode 100644 index 0000000000000000000000000000000000000000..e98dce249868cc7c4267f1b13d98a21f9b627e3a GIT binary patch literal 1198 zcma)5O;Zy=5Pg$uc0*hR0s%!(P(Bhsf`IrDMInMl6R-raEH4hr8WzKDYS~bF_m5a* zm1jK!N~^5$>i_URcmm&$C?FoJO=fz!`*pwW>G{6<`73}4%o_*^^jY4j{nQE8@?O!g zW?z>}(v^YZxoOJMU0n=($1NJr1e(_6mQ2%LOfRgg+g2c;-*j9jm=XvlQ_BKcmce2O zqrpT3xS-5E92Hg6fFXXA%S)SZAXfz`I|V6GjzAsq(9A)v}7)ojo~c140H;# z9K_GkLt26Dn>dH_EUst=tj+cvYgv{mEKW;iQ#k`Y0__K|TAG=PQ(CosMdYH1Ui1kV zTMD)CQlLM1sEk@~GpR$WdSx+mV?cE_DUdh}`BS;_7&I}2Vby?g*>+b2I?3u-usWZN zLX4P5V^km-c(q6Zt;ypM`X(@DVjL5UUb5X{u(p5mxdu$)nt`iF+xuoSus2Lx#|?UU z74|k!qv3ezN1UpF$!xj7us1Pf;MVVEA2pk}t?D((3Q^*vYtk=rSX%yZ^~|#w_-e@h zZa-&6_wCI}i7bS}e@-A|k-o?ZL@cl3D#NO zuSnmo5yKr!@5gyek1T2HSioIMAw)6DZ;nyp7{xszG)C-2j=Bi@)q@9=bUY-!4cabF W7)bCZc5zw=(e{%W1@g3pQ1}I6XbCU? literal 0 HcmV?d00001 diff --git a/target/test-classes/codeWithLogicExplanation/StringCompresssed.class b/target/test-classes/codeWithLogicExplanation/StringCompresssed.class new file mode 100644 index 0000000000000000000000000000000000000000..907f7e013ebb5d9d2098914407e831773feed52a GIT binary patch literal 2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