×

Rectangular Numbers in Java

In this tutorial, we will understand the meaning of a rectangular number in Java with the aid of examples, illustrations, and implementations. It is one of the popular coding interview questions.

Meaning

Rectangular numbers are known by other names such as -Pronic Number, oblong number, rectangular number, or heteromecic number.

A rectangular number is a special numberthat is the product of two consecutive integers, that is, n and (n + 1). The product can be expressed as n*(n+1)

It can also be understood that rectangular numbers are those numbers that can be arranged to form a rectangle.

Examples:

Some of the initial pronic numbers include: 0, 2, 6, 12, 20, 30, 42, 56, 72, 90, 110, 132, 156, 182, 210, 240, 272, 306, 342, 380, 420, 462…..

2 is considered the pronic number because it is the product of 2 consecutive numbers.

2 = 1 * 2      

It is forming a rectangle of 1 row and 2 columns.

Similarly, 6 is considered the pronic number because it is the product of 2 consecutive numbers.

6 = 2 * 3

It is forming rectangle of 2 row and 3 columns.

Similarly, 12 is considered the pronic number because it is the product of 2 consecutive numbers.

12 = 3 * 4

It is forming a rectangle of 3rows and 4 columns.

Similarly, 30 is considered the pronic number because it is the product of 2 consecutive numbers.

30 = 5*6

Here, it is forming a rectangle of 5rows and 6 columns.

Similarly, 56 is considered the pronic number because it is the product of 2 consecutive numbers.

56 = 7 * 8

It is forming a rectangle of 7 rows and 8 columns.

42 is considered the pronic number because it is the product of 2 consecutive numbers.

42 = 6 * 7

It is forming a rectangle of 6rows and 7 columns.

72 is considered the pronic number because it is the product of 2 consecutive numbers.

72 = 8 * 9

It is forming a rectangle of 8rows and 9 columns.

0 is considered the pronic number because it is the product of 2 consecutive numbers.

0 = 0 * 1

Numbers those are not rectangular

3 is not considered as a rectangular number because it is not the product of 2 consecutive numbers.

3 = 3 * 1

Here, 1 row and 3 columns are being formed. Thus, the criteria for being a rectangular number get failed. So, it is not a rectangular number.

5 is not considered as a rectangular number because it is not the product of 2 consecutive numbers.

5 = 5 * 1

In the same way, here 1 row and 5 columns are being formed, violating the criteria of a rectangular number. So, it is also not a rectangular number.

7 is not considered as a rectangular number because it is not the product of 2 consecutive numbers.

7 = 7 * 1

In the same way, here 1 row and 7 columns are being formed, violating the criteria of a rectangular number. So, it is also not a rectangular number.

9 is also not considered as a rectangular number because it does not form a rectangle with consecutive numbers of rows and columns.

Implementation

Now, we will see a java code to understand the meaning of the rectangular number in a more practical way.

Code

//A program to check whether an entered no. is pronic or not


import java.util.*;
class RectangularNumber
{
    public static void main(String args[])
    {
        Scanner sc = new Scanner(System.in);


System.out.print("Enter any number : ");
        int num = sc.nextInt();
        int flag = 0;


        for(int j=0; j<num; j++)
        {
            if(j*(j+1) == num)
            {
                flag = 1;
                break;
            }
        }


        if(flag == 1)
System.out.println(num+" is a Rectangular Number.");
        else
System.out.println(num+" is not a Rectangular Number.");      
    }
}

Outputs:

1.

Rectangular Numbers in Java

Explanation: The no. 87 is checked and is found that it is not a rectangular number.

2.

Rectangular Numbers in Java

Explanation: The no. 6 is checked and is found that it is a rectangular number

Summary

In this tutorial, we tried to understand what is meant by rectangular number, saw a good number of examples, and further saw its implementation in java.


Related Topics

Java ArrayList

Java ArrayList Class A Java ArrayList class is a dynamic array which is used to store the elements. It is a part of collection framework. It implements the List Interface and inherits the...

12 minutes read.

Polygonal Number in Java

What does a Java Polygonal Number Mean? In mathematics, a polygonal number refers to a number that is expressed through dots or pebbles arranged in a regular polygonal pattern. Alphas are...

4 minutes read.

Types of Assignment Operators in Java

In this tutorial, we are going to study assignment operators and their types in Java language. Before proceeding to the types, let us know the term ‘assignment operator’.  The assignment...

5 minutes read.

Bully Algorithm code in Java

Election algorithms include the bully algorithm, mainly used to select a coordinate. To find a coordinator in a distributed system that can carry out the tasks required by other processes,...

4 minutes read.

Java Database Connectivity with MySQL

In this tutorial, we will learn how to connect Database with MySQL in Java. 5 Steps to Connect to the Database in Java Load the driver (or) Register the driver classEstablish a...

4 minutes read.

How to increment and decrement date using Java?

Before understanding how to increment and decrement the date, one must know about the Calendar class in Java. The Java calendar class offers methods for converting dates between a given moment...

3 minutes read.

How to get the current date and time in Java

Introduction: In this article, we are going to discover many processes for Getting the existing-day Date and Time in Java. Most programs require timestamping events or showing date/times, among many...

3 minutes read.

ConcurrentSkipListSet in Java

ConcurrentSkipListSet is a class that is a part of collection framework in Java.It has been available since Java version 1.6. ConcurrentSkipListSet  is a scalable concurrent NavigableSet implementation based on a ConcurrentSkipListMap.The...

16 minutes read.

How to remove last character from String in Java

In java, there are predominantly three classes connected with the string. The classes are String, StringBuilder, and StringBuffer class that gives techniques connected with string control. Eliminating the first and...

5 minutes read.

Process and Thread in Java

Process It is a program that is running on your computer. The process is a heavy-weight, which takes memory separately to other processes. The process may be a small background task like spell-checker; it...

11 minutes read.

Convert JSON to Map in Java

JACKSON and GSON libraries are two extremely capable JSON-related libraries offered by Java. To efficiently work with the returned JSON data, we frequently need to convert JSON responses into a...

6 minutes read.

Moran Numbers in Java

In this article, we will be acknowledged about the moran numbers in Java, how they are formed, what are the approaches to achieve the moran numbers. Moran Number A moran numbers are...

3 minutes read.

Java Byte intValue() method

The intValue()  method of Java Integer class returns an int value for this Integer.  Syntax public int intValue()  Parameters NA  Specified by This method is specified by intValue in class Number  Return Value This method returns the numeric...

1 minute read.

Java Final Keyword

In Java, the last keyword is used to limit the user. The applications of the java final keyword have large range of usage in program development. Last can be: variablemethodclass A final...

3 minutes read.

Comparator vs Comparable in Java

Comparator Vs Comparable in Java In Java, sorting of primitive data types can be done using different inbuilt functions that are available. But for sorting the collection of objects or types...

4 minutes read.

this keyword in Java

The 'this' keyword is an essential notion in Java. We'll go through the 'this' keyword in depth and provide some examples of how it's used in Java. In Java, the term...

5 minutes read.

Best Java IDE

Applications for desktop, workplace, smartphone, and the internet can be created using Java, one of the most popular programming languages. Java will undoubtedly be a popular programming language for so...

5 minutes read.

Java Binary to Hexadecimal

Converting between types in programming is an important task. Moving from one kind to another kind conversion is occasionally necessary. We have discussed numerous conversion types in the section on...

3 minutes read.

Java DatagramSocket and Java DatagramPacket

Datagrams TCP/IP style networking specifies a serialized, predictable, and reliable stream of data in the form of a packet. Servers and clients communicate through a reliable channel, such as TCP socket, have a dedicated...

6 minutes read.

Practical Number in Java

In this tutorial, we will understand what is meant by practical numbers. We will understand it throughthe aid of examples and implementation in a java programming language. The practical numbers...

5 minutes read.