Largest and Smallest N | Java program to find the largest and smallest N - digit numbers in Octal Number System ; Function to return the largest N - digit number in Octal Number System ; Append '7' N times ; Function to return the smallest N - digit number in Octal Number System ; Append '0' ( N - 1 ) times to 1 ; Function to print the largest and smallest N - digit Octal number ; Driver code ; Function Call
class GFG { static String findLargest ( int N ) { String largest = strings ( N , '7' ) ; return largest ; } static String findSmallest ( int N ) { String smallest = "1" + strings ( ( N - 1 ) , '0' ) ; return smallest ; } private static String strings ( int N , char c ) { String temp = " " ; for ( int i = 0 ; i < N ; i ++ ) { temp += c ; } return temp ; } static void printLargestSmallest ( int N ) { System . out . print ( " Largest : ▁ " + findLargest ( N ) + "NEW_LINE"); System . out . print ( " Smallest : ▁ " + findSmallest ( N ) + "NEW_LINE"); } public static void main ( String [ ] args ) { int N = 4 ; printLargestSmallest ( N ) ; } }