Archives: Logical Programs

How to swap two numbers without using a third variable in Java?

Swapping two numbers can be also known as exchanging the numbers between two variables. The swapping of two numbers without using a third variable or a temporary variable can be done by following the below simple steps: For example, letโs take two numbers x=20 (first variable) and y=30 (second variable), Add both number (x+y) and โฆ

How to check whether a number is a Palindrome number or not in Java?

A Palindrome number is a special type of number. After reversing a number, if the number will be the same as the original number then that number will be called a Palindrome number. For example, some Palindrome number is as follow: 121, 242, 12321, 515, 8448, 2345432, etc. Letโs see the logic to check whether โฆ

How to reverse a number in Java?

The reverse of a given number is simply called as when the number is 123, the reverse number should be 321. In java, there are multiple ways to calculate the reverse of a given number. Here we will discuss a simple way using a while loop. Follow the below steps to calculate the reverse of โฆ

How to check whether a number is an Armstrong number or not in java?

A special positive number whose sum of cubes of its individual digit is equal to that number is called an Armstrong Number.ย  Example #1,The number 153 is an Armstrong number. It can be checked as follow:(1)3 + (5)3 + (3)3 => 1 + 125 + 27 => 153 Example #2,The number 371 is also an โฆ

How to check whether a number is a perfect number or not in java?

Theย Perfect Numberย is a special type of positive number. When the number is equal to the sum of its positive divisors excluding the number, it is called a Perfect Number. For example, 28 is the perfect number because when we sum the divisors of 28, it will result in the same number. The divisors of 28 โฆ

How to check whether a number is a prime number or not in java?

A Prime number is a number that is divisible by only 1 and itself. A prime number canโt be divided by zero, because numbers divided by zero are undefined. The smallest prime number is 2, which is also the only even prime. Letโs see the logic to check whether a number is a prime number โฆ

How to calculate the factorial of a given number in java?

The multiplication of all positive integers which are less than or equal to the given positive number is called the factorial of that given integer number. Example #1, The factorial of the number 5 can be calculated as follow: 1 * 2 * 3 * 4 * 5 = 120 Example #2, The factorial of โฆ

How to print a Fibonacci series up to a given number in Java?

Fibonacci series is a special type of series in which the next number is the sum of the previous two numbers. For example, 1 1 2 3 5 8 13 21โฆ. up to a given number. Solution #1 : Using Recursion FibonacciSeriesWithRecursion.java OUTPUT: Enter number up to which Fibonacci series to print:120 1 1 2 โฆ