Archives: Logical Programs

Java Hello world program

In this blog post, you will learn how to write the ‘Hello world’ program, compile it, and execute it in java language. The ‘Hello world’ program is a very simple program that will print the ‘Hello world‘ on the screen. Required software dependency The below-listed software is required for writing, compiling, and executing the ‘Hello …

Java Hello world program Read More »

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 »