Lucas Numbers | Iterative Java program to find n 'th Lucas Number ; Iterative function ; declaring base values for positions 0 and 1 ; generating number ; Driver Code
class GFG { static int lucas ( int n ) { int a = 2 , b = 1 , c , i ; if ( n == 0 ) return a ; for ( i = 2 ; i <= n ; i ++ ) { c = a + b ; a = b ; b = c ; } return b ; } public static void main ( String args [ ] ) { int n = 9 ; System . out . println ( lucas ( n ) ) ; } }