Archives: Logical Programs

How to swap two strings without using the third variable in java?

The logic that can be implemented for this program is as follow: Step1: Concatenate both strings and store them in the first variable. Ex. s1 = s1 + s2 Step2: s2 = s1.substring(0, s1.length() – s2.length()); Step3: s1 = s1.substring(s2.length()); Solution Let’s see the complete logic below: SwapTwoString.java OUTPUT: Before swap :: s1=>abc, s2=>xyz123After swap …

How to swap two strings without using the third variable in java? Read More »

How to count the occurrence of the given character in a string in java?

Let’s assume the string is apple and the given character is p to count the occurrence then the output of this program should be as follow: p => 2 times Solution CountGivenCharacter.java OUTPUT: Please enter a string to count the given character:examplePlease enter a character to count:ee => 2 times

How to reverse a string without using the reverse() method in java?

In this section, you will see how to reverse a string without using the predefined method reverse(). Here we have explained the two solutions for the string reverse using recursion and without using recursion. Let’s see both solutions below: Solution #1 : Using Recursion ReverseStringWithRecursion.java OUTPUT: Please enter a string to reverse:javacodepointReverse of the given …

How to reverse a string without using the reverse() method in java? Read More »

Top 50 Pattern printing programs in java

We have categorized all the patterns into three categories: Star Patterns Number Patterns Character Patterns or Alphabet Patterns Star Patterns Number Patterns Character or Alphabet Patterns 1.) Star Patterns Pattern-1 (Right Triangle) StarPattern1.java Pattern-2 (Down Right Triangle) StarPattern2.java Pattern-3 (Mirrored Right Triangle) StarPattern3.java Pattern-4 (Down Mirrored Right Triangle) StarPattern4.java Pattern-5 (Right Pascal’s Triangle) StarPattern5.java Pattern-6 …

Top 50 Pattern printing programs in java Read More »

Top 30 star pattern program in Java

In this article, you will see the top 30-star pattern programs in Java. Here we tried to provide the logic with a clear explanation for the Java professional. Pattern programs are frequently asked in the fresher interview to check their logical skills. Before going through the logic for all these pattern programs, we recommend you …

Top 30 star pattern program in Java Read More »