Trimorphic Number | Java program to check if a number is Trimorphic ; Function to check Trimorphic number ; Store the cube ; Start Comparing digits ; Return false , if any digit of N doesn ' t ▁ match ▁ with ▁ ▁ its ▁ cube ' s digits from last ; Reduce N and cube ; Driver code
class GFG { static boolean isTrimorphic ( int N ) { int cube = N * N * N ; while ( N > 0 ) { if ( N % 10 != cube % 10 ) return false ; N /= 10 ; cube /= 10 ; } return true ; } public static void main ( String [ ] args ) { int N = 24 ; if ( isTrimorphic ( N ) == true ) System . out . println ( " trimorphic " ) ; else System . out . println ( " not ▁ trimorphic " ) ; } }