Nonagonal number in Java
Figureate numbers with the form n(7n-5)/2 are known as nonagonal numbers. 7n+3 will be a triangular number if n is a nonagonal number. The nonagon is included in the idea of triangular and square numbers. It is often referred to as an enneagonal or 9-gonal number. The sequence is A001106 from the OEIS.
The first few numerical values 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
Program for Nonagonal number using Java
Nonagonal.java
// importing required packages
import java. util. * ;
import java.io . * ;
// public class is declared with the name Nonagonal
public class Nonagonal
{
// static method is declared to find the Nonagonal number in the required position
static int Nonagonal ( int k )
{
// returning the value
return k * (7 * k - 5) / 2;
}
// Main section where execution of the program starts
public static void main(String args[])
{
// Creating object for scanner class to take inputs from the user during run time
Scanner sc = new Scanner ( System . in ) ;
// Enter the position
System . out . println ( " Enter the term position you want to find: " ) ;
// Storing the value in the integer variable n
int n = sc . nextInt ( ) ;
// printing the nonagonal number
System.out.println ( " The "+n+ " nonagonal number is: "+ Nonagonal(n) ) ;
}
}
Output

Types of Nonagonal Numbers
Centered Nonagonal Numbers
The following formula may be used to determine it as a figurate number:
Nn = 9n(n-1)/2+1
The sequence is A060544 from the OEIS. In the sequence A000217, it should be noted that each and every third triangular number is a nonagonal number.
Following are the centered nonagonal numbers:
1, 10 , 28 , 55 , 91 , 136 , 190 , 253 , 325 , 406 , 496 , 595 , 703 , 820 , 946 , 1081 , 1225, 1378, 1540, 1711, 1891, 2080, 2278
Program for Centered Nonagonal number using Java
CenteredNon.java
// importing the required packages
import java. util . Scanner ;
import java . io .* ;
// public class declaration
public class CenteredNon
{
// static method Nonagonal is declared
static int Nonagonal ( int n )
{
// return the centered nonagonal number using the formula 9 * n * (n-1) / 2 + 1 ;
return 9 * n * ( n-1 ) / 2 + 1 ;
}
// Main section where execution of the program starts
public static void main ( String args[ ] )
{
// creating object for scanner class to take inputs from the user during run time
Scanner sc = new Scanner ( System . in ) ;
System . out . println ( " Enter term position: " ) ;
int n=sc . nextInt ( ) ;
System . out . println ( " The " + n + " rd/th centered nonagonal number is : " + Nonagonal ( n ) ) ;
}
}
Output

Second 9-gonal
The following formula may be used to find it as a figurate number:
Nn = n * ( 7 * n + 5 ) / 2
The sequence is A179986 from the OEIS.
Program for Second 9-gonal number using Java
Second9gonal.java
// importing the required packages
import java . util . Scanner ;
import java . io . * ;
// public class declaration
public class Second9gonal
{
// static method Nonagonal is declared
static int Nonagonal ( int n )
{
// return the second9 gonal number using the formula n * ( 7 * n+5 ) / 2 ;
return n * ( 7 * n + 5) / 2 ;
}
// Main section where execution of the program starts
public static void main ( String args [ ] )
{
// creating object for scanner class to take inputs from the user during run time
Scanner sc = new Scanner ( System . in ) ;
System . out . println ( "Enter the position : " );
// storing the position in an integer variable n
int n = sc . nextInt ( ) ;
System . out . println ( "The " + n + " centered nonagonal number is: " + Nonagonal ( n ) ) ;
}
}
Output

3-Times Nonagonal Numbers
The OEIS sequence A152759 is another example of a 9-gonal or nonagonal number. But it repeats the sequence A001106 three times. This indicates that any of the following formulas may be used to compute the 3-by-9-gonal:
Nn = 3 * ( n * ( 7 * n-5 ) / 2 )
Program for 3 time Nonagonal number
Threetimesnonagonal.java
// importing the required packages
import java . util . Scanner ;
import java . io .* ;
// public class declaration
public class Threetimesnonagonal
{
// static method Nonagonal is declared
static int Nonagonal ( int n )
{
// return the centered nonagonal number using the formula 3 * ( n * ( 7 * n-5) /2 );
return 3 * ( n * ( 7 * n-5) / 2 ) ;
}
// Main section where execution of the program starts
public static void main( String args[ ] )
{
// creating object for scanner class to take inputs from the user during run time
Scanner sc = new Scanner( System . in);
System . out . println ( "Enter position : " ) ;
// storing the value of the position in an integer variable n
int n=sc . nextInt ( );
System . out . println ( " The "+ n + " th 3 times nonagonal number is : "+ Nonagonal(n) ) ;
}
}
Output

Twice Nonagonal Number
The sequence is A139268 from the OEIS. We may use the following formula to determine the twice-nonagonal numbers:
Nn = n (7n-5)
Program for Twice Nonagonal in Java
TwiceNonagonal.java
// importing the required packages
import java . util . Scanner ;
import java . io . * ;
// public class declaration
public class TwiceNonagonal
{
// static method Nonagonal is declared
static int Nonagonal ( int n )
{
// return the centered nonagonal number using the formula 3 * ( n * ( 7 * n-5 ) / 2 ) ;
return n * ( 7 * n-5 ) ;
}
// Main section where execution of the program starts
public static void main (String args [ ] )
{
// creating object for scanner class to take inputs from the user during run time
Scanner sc = new Scanner ( System . in ) ;
System . out . println ( " Enter the position : " ) ;
// storing it to an integer variable n
int n = sc . nextInt ( ) ;
System . out . println ( " The " + n + " th 2 times nonagonal number is : "+ Nonagonal ( n ) ) ;
}
}
Output

Nonagonal Palindromic Numbers
Numbers that may be written both ways (from the right to the left and from the left to the right) without affecting their value are known as palindromic nonagonal numbers. A palindromic nonagonal number cannot have an even number of digits. A08272 is the OEIS sequence.
Program for Nonagonal Palindrome
PalindromeNonagonal.java
import java . util . Scanner ;
public class PalindromeNonagonal
{
public static void main ( String [ ] args )
{
int n , rev = 0, rem ;
Scanner sc = new Scanner ( System.in ) ;
System . out . print ( " Enter the number you want to check : " ) ;
n=sc . nextInt () ;
int a = n ;
// Logic to reverse a number
while (n != 0 )
{
rem = n % 10 ;
rev = rev * 10 + rem ;
n = n/10 ;
}
// a is equal to rev then it will print the given number is a nonagonal palindrome
if (a == rev)
{
System . out . println ( a + " is nonagonal palindrome " ) ;
}
// a is not equal to rev then it will print the given number is not a nonagonal palindrome
else
{
System . out . println ( a + " is not nonagonal palindromic " ) ;
}
}
}
Output
