Find the largest Alphabetic character present in the string | Java program to Find the Largest Alphabetic Character present in the string of both uppercase and lowercase English characters ; Function to find the Largest Alphabetic Character ; Array for keeping track of both uppercase and lowercase english alphabets ; Iterate from right side of array to get the largest index character ; Check for the character if both its uppercase and lowercase exist or not ; Return - 1 if no such character whose uppercase and lowercase present in string str ; Driver code
public class Main { public static String largestCharacter ( String str ) { boolean [ ] uppercase = new boolean [ 26 ] ; boolean [ ] lowercase = new boolean [ 26 ] ; char [ ] arr = str . toCharArray ( ) ; for ( char c : arr ) { if ( Character . isLowerCase ( c ) ) lowercase = true ; if ( Character . isUpperCase ( c ) ) uppercase = true ; } for ( int i = 25 ; i >= 0 ; i -- ) { if ( uppercase [ i ] && lowercase [ i ] ) return ( char ) ( i + ' A ' ) + " " ; } return " - 1" ; } public static void main ( String [ ] args ) { String str = " admeDCAB " ; System . out . println ( largestCharacter ( str ) ) ; } }