Finding Number of Digits in a Number

The following Java program finds the number of digits in a number. This program converts the number to a string and then prints its length, public class DigitsInNumber { public static void main(String[] args ) { int number = 94487; String s = String.valueOf(number); System.out.println(number + " has "+ s.length()+" digits"); } } The following […]

Program to Find all Armstrong Numbers in a Range

A number n is said to be an Armstrong number if it is equal to the n-th power of its digits. For example consider the number 407, The number of digits(n) is 3. The sum of 3rd power of the digits = 4^3+0^3+7^3 = 407. Hence 407 is an Armstrong number. All single digit numbers […]

Program to Check Armstrong Number in Java

What is Armstrong number? An n digit number is said to be an Armstrong number if the sum of n-th power of its digits is the n digit number itself. For example consider the number 371, The number of digits = 3 The sum of 3rd power of digits = 3^3 + 7^3 + 1^3 […]

Factorial Program in Java

In mathematics, the factorial of an integer is defined as the product of all positive integers less than or equal to the integer. Factorial of integer n is denoted by n!. For example, factorial of 5 is (5!) = 5 * 4 * 3 * 2 * 1 = 120. Factorial Program in Java The […]

Fibonacci Series in Java

Fibonacci series is a sequence of numbers where a number in the sequence is the sum of two previous numbers. By definition, the first two numbers in the series are 0 and 1. The following are the first 12 numbers in the Fibonacci series, 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, […]