Adding Two Numbers in Java

Adding two numbers is one of the first programming problems given when someone is learning a new programming language.  This program enables the programmer to focus on the language syntax since the algorithm for addition is trivial. It also demonstrates use of input/output, program structure, built-in utility libraries and basic language features like statements, comments […]

Find Number of Words in a String in Java

Finding number of a words in a String is a common problem in text processing. The Java string API and regular expression support in Java makes it a trivial problem. Finding Word Count of a String in Java The following Java program uses split() method and regular expressions to find the number of words in […]

Removing a String from a String in Java

One of the common text processing requirements is to remove a specific substring from a given string. For example, let us assume we have string "1,2,3,4,5" and we want to remove "3," from it to get the new string "1,2,4,5". The following Java program demonstrates how this can be achieved. Java Program to Remove a […]

Finding Triangular Numbers in Java

Definition of Triangular Number Triangular number of a natural number n is the sum of all natural numbers from 1 to n. For example, Triangular number of 5 = 1 + 2 + 3 + 4 + 5 = 15.  Mathematically, It is known as triangular numbers since it is the total number of dots […]

Program to Print Pascal Triangle in Java

Pascal’s triangle is a set of numbers arranged in the form of a triangle. Each number in a row is the sum of the left number and right number on the above row. If a number is missing in the above row, it is assumed to be 0. The first row starts with number 1. […]