Program to find the largest and smallest ASCII valued characters in a string | Java program to find largest and smallest characters in a string . ; function that return the largest alphabet . ; initializing max alphabet to ' a ' ; find largest alphabet ; returning largest element ; function that return the smallest alphabet ; initializing smallest alphabet to ' z ' ; find smallest alphabet ; returning smallest alphabet ; Driver Code ; Input String ; Calculating size of the string ; calling functions and print returned value
public class GFG { static char largest_alphabet ( String a , int n ) { char max = ' A ' ; for ( int i = 0 ; i < n ; i ++ ) if ( a . charAt ( i ) > max ) max = a . charAt ( i ) ; return max ; } static char smallest_alphabet ( String a , int n ) { char min = ' z ' ; for ( int i = 0 ; i < n - 1 ; i ++ ) if ( a . charAt ( i ) < min ) min = a . charAt ( i ) ; return min ; } public static void main ( String args [ ] ) { String a = " GeEksforGeeks " ; int size = a . length ( ) ; System . out . print ( " Largest ▁ and ▁ smallest ▁ alphabet ▁ is ▁ : ▁ " ) ; System . out . print ( largest_alphabet ( a , size ) + " ▁ and ▁ " ) ; System . out . println ( smallest_alphabet ( a , size ) ) ; } }