Number obtained by reducing sum of digits of 2 N into a single digit | Java program for the above approach ; Function to find the number obtained by reducing sum of digits of 2 ^ N into a single digit ; Stores answers for different values of N ; Driver Code
import java . util . * ; class GFG { static int findNumber ( int N ) { int [ ] ans = { 1 , 2 , 4 , 8 , 7 , 5 } ; return ans [ N % 6 ] ; } public static void main ( String args [ ] ) { int N = 6 ; System . out . println ( findNumber ( N ) ) ; } }