Archives: Logical Programs

Java Program to Multiply two Numbers

In this article, you will learn how to write a Java program to multiply two numbers. Here, you will see multiple solutions for it such as multiplying two static numbers, multiplying two dynamically given numbers, and multiplying two Numbers using command-line arguments. Multiplication of two numbers in java The multiplication of two numbers in java …

Java Program to Multiply two Numbers Read More »

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