Check if uppercase characters in a string are used correctly or not | package whatever do not write package name here ; Function to check if the character c is in lowercase or not ; Function to check if the character c is in uppercase or not ; Utility function to check if uppercase characters are used correctly or not ; Length of string ; If the first character is in lowercase ; Otherwise ; Check if all characters are in uppercase or not ; If all characters are in uppercase ; Check if all characters except the first are in lowercase ; Function to check if uppercase characters are used correctly or not ; Stores whether the use of uppercase characters are correct or not ; If correct ; Otherwise ; Driver Code ; Given string ; Function call to check if use of uppercase characters is correct or not
import java . io . * ; class GFG { static boolean isLower ( char c ) { return c >= ' a ' && c <= ' z ' ; } static boolean isUpper ( char c ) { return c >= ' A ' && c <= ' Z ' ; } static boolean detectUppercaseUseUtil ( String S ) { int N = S . length ( ) ; int i ; if ( isLower ( S . charAt ( 0 ) ) ) { i = 1 ; while ( i < N && isLower ( S . charAt ( i ) ) ) ++ i ; return i == N ? true : false ; } else { i = 1 ; while ( i < N && isUpper ( S . charAt ( i ) ) ) ++ i ; if ( i == N ) return true ; else if ( i > 1 ) return false ; while ( i < N && isLower ( S . charAt ( i ) ) ) ++ i ; return i == N ? true : false ; } } static void detectUppercaseUse ( String S ) { boolean check = detectUppercaseUseUtil ( S ) ; if ( check ) System . out . println ( " Yes " ) ; else System . out . println ( " No " ) ; } public static void main ( String [ ] args ) { String S = " GeeKs " ; detectUppercaseUse ( S ) ; } }