Program for Perrin numbers | Optimized Java program for n 'th perrin number ; Driver code
import java . io . * ; class GFG { static int per ( int n ) { int a = 3 , b = 0 , c = 2 , i ; int m = 0 ; if ( n == 0 ) return a ; if ( n == 1 ) return b ; if ( n == 2 ) return c ; while ( n > 2 ) { m = a + b ; a = b ; b = c ; c = m ; n -- ; } return m ; } public static void main ( String [ ] args ) { int n = 9 ; System . out . println ( per ( n ) ) ; } }