Nonagonal Number in JavaIn this section, we will learn what is a nonagonal number and also create Java programs to check if the given number is a nonagonal number or not. The nonagonal number program is frequently asked in Java coding interviews and academics. Nonagonal NumberNonagonal numbers are the figurate numbers of the form n(7n5)/2. If n is a nonagonal number, then 7n+3 will be a triangular number. It extends the concept of triangular and square numbers to the nonagon. It is also known as a 9gonal or enneagonal number. It is an OEIS sequence A001106. It counts the number of dots in a pattern of n nested nonagons that has 9sides. All share a common corner, where the ith nonagon in the pattern has sides made of i dots spaced one unit apart from each other. N_{2} Types of Nonagonal Numbers
Let's discuss each in detail. Nonagonal Number ExampleFirst few nonagonal numbers are: 1, 9, 24, 46, 75, 111, 154, 204, 261, 325, 396, 474, 559, 651, 750, 856, 969, 1089, 1216, 1350, 1491, 1639, 1794, 1956, 2125, 2301, 2484, 2674, 2871, 3075, 3286, 3504, 3729, 3961, 4200, 4446, 4699, 4959, 5226, 5500, 5781, 6069, 6364. Formula to Find Nonagonal NumberWe can find the nth nonagonal number by using the following formula:
N_{n} = n (7n  5) / 2
Let's implement the above steps in a Java program. Nonagonal Number Java ProgramNonagonalNumberExample.java Output: Enter the term you want to find: 4 The 4 rd/th nonagonal number is: 46 Centered Nonagonal NumbersIt is also a figurate number that can be calculated by using the following formula:
N_{n} = 9n(n1)/2+1
It is an OEIS sequence A060544. Note that every third triangular number of the sequence A000217 is a nonagonal number. Centered Nonagonal Number ExampleFirst few centered nonagonal numbers are: 1, 10, 28, 55, 91, 136, 190, 253, 325, 406, 496, 595, 703, 820, 946, 1081, 1225, 1378, 1540, 1711, 1891, 2080, 2278, 2485, 2701, 2926, 3160, 3403, 3655, 3916, 4186, 4465, 4753, 5050, 5356, 5671, 5995, 6328, 6670, 7021, 7381, 7750, 8128, 8515, 8911, 9316. Formula to Find Centered Nonagonal NumberWe can calculate the centered nonagonal numbers by using the following formula:
N_{n} = 9n(n1)/2+1
Centered Nonagonal Number Java ProgramCenteredNonagonalNumberExample.java Output: Enter the term you want to find: 25 The 25 rd/th centered nonagonal number is: 2701 Second 9gonal or Nonagonal NumberIt is also a figurate number that can be find by using the following formula:
N_{n} = n*(7*n+5)/2
It is an OEIS sequence A179986. Second 9gonal Number ExampleFirst few 9gonal numbers are: 6, 19, 39, 66, 100, 141, 189, 244, 306, 375, 451, 534, 624, 721, 825, 936, 1054, 1179, 1311, 1450, 1596, 1749, 1909, 2076, 2250, 2431, 2619, 2814, 3016, 3225, 3441, 3664, 3894, 4131, 4375, 4626, 4884, 5149, 5421, 5700, 5986, 6279, 6579, 6886. Note that the sequence is the bisection of the OEIS sequence A118277 (only even part). Second 9gonal Number Java ProgramSecondNonagonalNumberExample.java Output: Enter the term you want to find: 35 The 35 rd/th second 9gonal or nonagonal number is: 4375 3Times Nonagonal NumbersThere is another OEIS sequence A152759 that is also a 9gonal number or nonagonal number. But it is 3times of the sequence A001106. It means that we can calculate the 3 times 9gonal by using any of the following formula:
N_{n }= 3*(n*(7*n5)/2)
Or
N_{n }= (21n^2  15n)/2
Or
A001106(n)*3
3Times Nonagonal Numbers ExampleFirst few 3time 9gonal numbers are: 3, 27, 72, 138, 225, 333, 462, 612, 783, 975, 1188, 1422, 1677, 1953, 2250, 2568, 2907, 3267, 3648, 4050, 4473, 4917, 5382, 5868, 6375, 6903, 7452, 8022, 8613, 9225, 9858, 10512, 11187, 11883, 12600, 13338, 14097, 14877, 15678. 3Times 9gonal Number Java ProgramThriceNonagonalNumberExample.java Output: Enter the term you want to find: 10 The 10 rd/th 3times nonagonal number is: 975 Twice Nonagonal NumberIt is an OEIS sequence A139268. We can calculate the twice nonagonal numbers by using the following formula:
N_{n} = n(7n5)
Twice Nonagonal Number ExampleFirst few twice nonagonal numbers are: 2, 18, 48, 92, 150, 222, 308, 408, 522, 650, 792, 948, 1118, 1302, 1500, 1712, 1938, 2178, 2432, 2700, 2982, 3278, 3588, 3912, 4250, 4602, 4968, 5348, 5742, 6150, 6572, 7008, 7458, 7922, 8400, 8892, 9398, 9918, 10452, 11000. Twice Nonagonal Number Java ProgramTwiceNonagonalNumberExample.java Output: Enter the term you want to find: 26 The 26 rd/th twice nonagonal number is: 4602 Palindromic Nonagonal NumbersPalindromic nonagonal numbers are numbers that can be written from both sides (right to left and left to right) without changing the value. A number that has an even number of digits cannot be a palindromic nonagonal number. It is an OEIS sequence A082723. Palindromic Nonagonal Number ExampleFirst few palindromic nonagonal numbers are: 1, 9, 111, 474, 969, 6666, 18981, 67276, 4411144, 6964696, 15444451, 57966975, 448707844, 460595064, 579696975, 931929139, 994040499, 1227667221, 9698998969, 61556965516, 664248842466, 699030030996, 99451743334715499. Palindromic Nonagonal Number Java programThe following Java program checks whether the given number is palindromic nonagonal or not. PalindromicNonagonalExample.java Output 1: Enter the number you want to check: 6964696 6964696 is palindromic nonagonal. Output 2: Enter the number you want to check: 4411144 4411144 is palindromic nonagonal.
Next TopicSexagesimalFormatter in Java
