Basic java programs
 17 November 17 November- Java program to print floyd’s triangle- In this post, we will see how to print Floyd’s triangle in java. Problem You need to print Floyd’s triangle as below for n=5. Floyd’s triangle **************** 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Floyd’s triangle in java Let’s create class "FloydTriangleMainExample.java" as below [crayon-69048af8bf4fc948602869/] When you […] 
 27 October 27 October- Count number of words in a string- In this post, we will see how to find number of words in a String. Problem Find the number of words in a String. For example: There are 6 words in below String welcome to java tutorial on Java2blog Algorithm The algorithm will be very simple. Initialize count with 1 as if there are no […] 
 20 January 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 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 = […] 
 01 August 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-69048af8bfa6d128313354/] When you run above program, you will get following output. [crayon-69048af8bfa70111728551/] Please go through Frequently asked java interview Programs for more such […] 
 01 August 01 August- Java program to reverse a String- In this post, we will see java program to reverse a String. There are many ways to do reverse a String in java, some of them are: Using for loop Declare empty String reverse. This will contain our final reversed string. Iterate over array using for loop from last index to 0th index Add character […] 
 01 August 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-69048af8bfc9a514402284/] When you run above program, you will get following output: [crayon-69048af8bfc9d079528096/] Third way is fastest of all. Please go through Interview programs in java  for more such programs. 
 10 July 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 09 July- Palindrome program in java- In this article, we will see how to implement palindrome program in java. A palindrome is a word, phrase, number, or other sequence of symbols or elements that reads the same forward or reversed. For example: 12121 is palindrome as it reads same forward or reversed. madam is also a palindrome . This is very […] 
