Ordinal Number in JavaIn 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 NumbersOrdinal 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:
All these numbers, 2^{nd} and 1^{st}, 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 NumbersWhenever we want to arrange something in a particular order, we determine the position, which in turn leads to the usage of ordinal numbers. SortingKnowingly 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 1^{st} position in the array. The second smallest element gets the 2^{nd} position in the array. Similarly, the 3^{rd} position is occupied by the 3^{rd} smallest element. When we sort in descending order, we put the largest element at the 1^{st} position of the array. The second largest element at the 2^{nd} position, and so on. In sorting, ordinals come into the picture because sorting is also a type of order. Example of Ordinal NumberIn 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 1^{st} 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 1^{st} rank. In the same way, other ranks can also be decided. Java ProgramThe following program generates the first 20 ordinal numbers. FileName: OrdinalNumber.java Output: 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.
Next TopicTetrahedral Number in Java
