Largest N digit Octal number which is a Perfect square | Java implementation to find the maximum N - digit octal number which is perfect square ; Function to convert decimal number to a octal number ; Array to store octal number ; Counter for octal number array ; Store remainder in octal array ; Print octal number array in reverse order ; Largest n - digit perfect square ; Driver code
import java . util . * ; import java . lang . * ; import java . io . * ; class GFG { static void decToOctal ( int n ) { int octalNum [ ] = new int [ 100 ] ; int i = 0 ; while ( n != 0 ) { octalNum [ i ] = n % 8 ; n = n / 8 ; i ++ ; } for ( int j = i - 1 ; j >= 0 ; j -- ) System . out . print ( octalNum [ j ] ) ; System . out . println ( "NEW_LINE"); } static void nDigitPerfectSquares ( int n ) { int decimal = ( int ) Math . pow ( Math . ceil ( Math . sqrt ( Math . pow ( 8 , n ) ) ) - 1 , 2 ) ; decToOctal ( decimal ) ; } public static void main ( String [ ] args ) { int n = 2 ; nDigitPerfectSquares ( n ) ; } }