• 01 November

    Java DecimalFormat example

    In this post, we will see how to format a number using DecimalFormat in java. DecimalFormat DecimalFormat class is subclass of NumberFormat class and it is used to format numbers by using specify formatting pattern.We can format a number upto 2 decimal place,upto 3 decimal place, using comma to separate digits. Creating DecimalFormat object [crayon-672957922899b373320092/] […]

  • 20 January

    How to check if number is power of two

    In this tutorial, we will see how to check if number is power of two. There are many approaches to check if number is power of two or not. Approach 1: It is very easy and straight forward approach. Run a while loop which checks for condition if n is even number (n%2==0). If n is […]

  • 15 December

    How to find GCD and LCM of two numbers in java

    In this post, we will see how to find Greatest common divisor(GCD) and Least Common Multiple(LCM) in java. GCD is calculated using Euclidean algorithm and LCM is calculated using reduction by GCD Eucid algo for calculating GCD is: Lets say , there are two numbers , a and b so GCD of two numbers = […]

  • 08 August

    Fibonacci series program in java

    If you want to practice data structure and algorithm programs, you can go through 100+ java coding interview questions. Fibonacci series is numerical series in which next number is sum of previous two numbers. For example : 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55 etc. There are two ways to print Fibonacci […]

  • 01 August

    Java program to check Armstrong number

    Armstrong number is a 3 digit number which is equal to sum of cube of its digits. For example: 371,153 In this post,  we will see how to check for Armstrong number in java. [crayon-6729579235288694455246/] When you run above program, you will get following output. [crayon-67295792352a5359475688/] Please go through Frequently asked java interview Programs for more such […]

  • 01 August

    How to swap two numbers without using temporary variables in java

    In this post, we will see how to swap two numbers without using temporary variables. There are three ways to do it. Java program: [crayon-672957923cf1d696547523/] When you run above program, you will get following output: [crayon-672957923cf28766656462/] Third way is fastest of all. Please go through Interview programs in java  for more such programs.

  • 10 July

    How to find prime factors of a number in java

    In this post, we will see how to find prime factors of a number in java. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. The prime factors of a number are all of the prime numbers that will exactly divide the given number. […]

  • 09 July

    java program to check prime number

    This is easy question. It may not be asked you directly, but you can use this program to create many other complex program. A prime number is a natural number greater than 1 that has no positive divisors other than 1 and itself. Program logic: If any number which is not divisible by any other […]