Java Programming Tips


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 […]

Jumble Word Game in Java

In Jumble word game, the computer program randomly picks up a secret word from a database of words and then shuffles it. The shuffled word is presented to the user and he is asked to guess the original word. The program ends when the user correctly guesses the word. The program also prints the number […]