Smallest and Largest N | Java implementation of the approach ; Function to print the largest and the smallest n - digit perfect cube ; Smallest n - digit perfect cube ; Largest n - digit perfect cube ; Driver code
class GFG { static void nDigitPerfectCubes ( int n ) { int smallest = ( int ) Math . pow ( Math . ceil ( Math . cbrt ( Math . pow ( 10 , ( n - 1 ) ) ) ) , 3 ) ; System . out . print ( smallest + " ▁ " ) ; int largest = ( int ) Math . pow ( Math . ceil ( Math . cbrt ( Math . pow ( 10 , ( n ) ) ) ) - 1 , 3 ) ; System . out . print ( largest ) ; } public static void main ( String args [ ] ) { int n = 3 ; nDigitPerfectCubes ( n ) ; } }