Java program to Add Subtract Multiply and Divide Two Binary Numbers

  • Write a java program for addition, subtraction, multiplication and division of two binary numbers.

In this java program, we will first take two binary numbers as input from user and convert it to decimal numbers using Integer.parseInt() method. Then we add, subtract, multiply and divide integers(corresponding to given binary numbers) and convert the result back to binary number using Integer.toBinaryString() method.

Java Program to Print Inverted Triangle Star Pattern

  • Java program to print reverse triangle star pattern.
Sample Output,
* * * * * * 
* * * * * 
* * * * 
* * * 
* * 
* 

Here is the matrix representation of the reverse star pattern. The row numbers are represented by i whereas column numbers are represented by j.

Java program reverse triangle star pattern

Java Program to Print Right Triangle Number Pattern

  • Java program to print right triangle number pattern.

A right triangle number pattern contains N space separated consecutive natural numbers in Nth row.

Sample triangle pattern of 5 rows.
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5 

Here is the matrix representation of the right triangle number pattern. The row numbers are represented by i whereas column numbers are represented by j.

Java program right triangle number pattern

Chain of Responsibility Pattern

Chain of responsibility design pattern creates a chain of request handlers to process a client's request. Each request handler in chain contains reference of next request handler in the chain. If one request handler cannot handle the request then it passes the request to the next handler in the chain. The request handlers in the chain will decide themselves on runtime that who will process the request and whether request needs to be forwarded to next handler in chain or not.

Template Design Pattern

In Template design pattern, we define the steps to execute an algorithm in a template method of an abstract base class without implementing some steps of the algorithm. It may contain the default implementation of the steps of algorithm that might be common for all or some of the subclasses. Its subclasses can override the specific steps of the algorithm as per requirement of subclasses but the algorithm execution sequence will be in the same way as defined by an abstract base class.

Proxy Design Pattern

In Proxy pattern, a proxy object represents a placeholder or surrogate which provides an interface to outer world to access the functionality of original object. A proxy object is simply means an object representing another object. Proxies are also known as handles, surrogates, and wrappers. This type of design pattern comes under structural design pattern.

Iterator Design Pattern

Iterator design pattern is one of the most popular and relatively simple design pattern which is commonly used in Java programming language. Iterator pattern provides a standard way to traverse a group of objects sequentially without exposing its internal implementation. The Iterator pattern takes the responsibility of traversal out of the collection of object and put it into an Iterator object that defines how to traverse these collection of objects.

Programming Languages Tutorials

Java Program Number Triangle Pattern Five

  • Java program to print number triangle pattern five using for loop.
Sample Output,
1 2 3 4 5 
1 2 3 4 
1 2 3 
1 2 
1 
1 2 
1 2 3 
1 2 3 4 
1 2 3 4 5

Java Program to Print Palindrome Pyramid Pattern

  • Java program to print palindrome pyramid pattern using for loop.
Sample Output,
     1
    121
   12321
  1234321
 123454321
12345654321