Author Archive


How to Check If a Triangle Can be Formed in Java

The sides of a triangle is constrained by the rule that the sum of any of its two sides is always bigger than the third side. Using this rule, we can find whether 3 sides given for a triangle is valid or not. The following sample Java program checks whether the given 3 sides can […]

How to Calculate Area of Triangle in Java

Area of any type of triangle can be calculated using the formula, Area = (b*h)/2, where b is the base of the triangle and h is the vertical height. The following diagram shows how to define base and vertical height of a triangle. The following sample Java program calculates the area of a triangle given […]

How to do Linear Search in Java

Linear search is one of the simplest algorithms for searching data. In linear search, the entire data set is searched in a linear fashion for an input data. It is a kind of brute-force search and in the worst case scenario, the entire data set will have to be searched. Hence worst case cost is […]

Fisher Yates or Durstenfeld Shuffle in Java

Fisher-Yates shuffle or Knuth shuffle is an algorithm for generating a random shuffle of a finite set. A typical use case would be shuffling the characters in a word or string. A modern efficient variant of Fisher-Yates is known as Durstenfeld algorithm. The Durstenfeld algorithm is,     for i from 0 to n − […]

How to Shuffle a Word in Java

Shuffling characters in a word involves randomly swapping letters in the word. It is used in vocabulary games such as Jumble game to improve English language skills. The following Java program shuffles a given word. The shuffling is achieved by randomly swapping characters 10 times (just an arbitrary number). It can be improved by replacing […]