Blog

Reading Individual digits of a Number in Java

In this post, I will show two ways of reading individual digits of a number in the Java language. The first method is using String, and it is the easier one. First, we change the input number to string in the following way just as we used previously to find the first digit of a […]

Read More

Java program to find Sum of Digits in a Number

The following program takes an integer number as an input and returns the sum of the individual digits. The number can be positive or negative. For instance, if the user enters 456, the program returns 15 which is the sum of 4 + 5 + 6. Additionally, the program makes sure the user enters only […]

Read More

Java Program to Find Perfect Number

The following Java program displays the available perfect numbers within a defined range of numbers. I use the Java for-loop to iterate between the minimum and maximum numbers to be checked. If a positive integer is equal to the sum of its divisors, we call it a perfect number, assuming the divisors don’t include the […]

Read More

How to Check if a Word is a Palindrome in Java

Palindrome in Java

In this post, I will show how to check if a word or sentence is palindrome in Java. If a word or sentence reads the same backwards or forward, we call it palindrome. For instance, if we reverse the word ‘madam’ we get the same word – ‘madam’. Words such as racecar, rotator, tattarrattat, which […]

Read More

Simple Java program to find Factorial of a number

The Java code below shows how to get the factorial of numbers. For instance 4! = 4 x 3 x 2 x 1 = 24. Since Zero factorial is defined to be one, i.e. 0! = 1, the loop starts from 1. The code below calculates the factorial of numbers from 1 to 10. public […]

Read More

Display number patterns using java

Here is a list of number patterns that you can produce using any programming language. I use Java in this post. I hope you will find these simple programs useful for programming challenges or assignments you might encounter. You can check also other pattern by clicking here. Here is the first pattern including the full […]

Read More
1 2