Javatpoint Logo
Javatpoint Logo

Ordinal Number in Java

In this section, we will learn what is ordinal number and also create Java programs to find ordinal numbers. The ordinal number program frequently asked in Java coding interviews and academics.

Ordinal Numbers

Ordinal numbers are used to represent the ranking. In other words, those numbers that define position/ ranking are treated as ordinal numbers. A few statements that use the ordinal numbers are:

  • India is the 2nd most populated country in the world, while China is 1st.
  • Usain Bolt secured the 1st rank in sprinting in the 2016 Rio Olympics.
  • The 1st rank in the Indian Air force is the Marshal of the Air Force.
  • The 1st person to walk on the moon is Neil Armstrong.
  • In the set S = {x, y, u, i, p, a, f, h, j, q, l}, x is the 1st
  • The 1st number of the cosine series is 1.

All these numbers, 2nd and 1st, are the ordinal numbers as they define the position or ranking. First, Second, Third, Fourth, Fifth, Sixth, …, etc., are examples of ordinal numbers.

Ordering and Ordinal Numbers

Whenever we want to arrange something in a particular order, we determine the position, which in turn leads to the usage of ordinal numbers.


Knowingly or unknowingly, we tend to find the position of elements (ordinals) to do the sorting. For example, if we are sorting an integer array in ascending order using selection sort, then we find that the smallest element is picked first. It is because the smallest element gets the 1st position in the array. The second smallest element gets the 2nd position in the array. Similarly, the 3rd position is occupied by the 3rd smallest element.

When we sort in descending order, we put the largest element at the 1st position of the array. The second largest element at the 2nd position, and so on. In sorting, ordinals come into the picture because sorting is also a type of order.

Example of Ordinal Number

In a school assembly or a queue, it is generally seen that students are arranged according to their height. The tallest student of the class is positioned at last, while the shortest student gets the 1st position in the queue. Thus, we are determining rank according to the height of students. In other words, the ordering of the students is done using the height of the students. Since, each student get a number known as ordinal number.

Similarly, marks can also be the criterion to determine rank. The student getting the highest mark gets the 1st rank. In the same way, other ranks can also be decided.

Java Program

The following program generates the first 20 ordinal numbers.



The 1st ordinal number.
The 2nd ordinal number.
The 3rd ordinal number.
The 4th ordinal number.
The 5th ordinal number.
The 6th ordinal number.
The 7th ordinal number.
The 8th ordinal number.
The 9th ordinal number.
The 10th ordinal number.
The 11th ordinal number.
The 12th ordinal number.
The 13th ordinal number.
The 14th ordinal number.
The 15th ordinal number.
The 16th ordinal number.
The 17th ordinal number.
The 18th ordinal number.
The 19th ordinal number.
The 20th ordinal number.

Youtube For Videos Join Our Youtube Channel: Join Now


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Trending Technologies

B.Tech / MCA