Program to accept String starting with Capital letter

20 May, 2021
Given a string str consisting of alphabets, the task is to check whether the given string is starting with a Capital Letter or Not.Examples:  
Input: str = "GeeksforGeeks"
Output: Accepted

Input: str = "geeksforgeeks"
Output: Not Accepted
 
Approach:  
Find the ASCII value of the first character of the string  
Check if this value lies in the range of [65, 90] or not  
If yes, print Accepted  
Else print Not Accepted  
Below is the implementation of the above approach:  
C++
Java
Python3
C#
Javascript
// C++ program to accept String// starting with Capital letter #include <iostream>using namespace std; // Function to check if first// character is Capitalint checkIfStartsWithCapital(string str){     if (str[0] >= 'A' && str[0] <= 'Z')        return 1;    else        return 0;} // Function to checkvoid check(string str){    if (checkIfStartsWithCapital(str))        cout << "Accepted\n";    else        cout << "Not Accepted\n";} // Driver functionint main(){    string str = "GeeksforGeeks";    check(str);     str = "geeksforgeeks";    check(str);     return 0;}
// Java program to accept String// starting with Capital letterclass GFG{         // Function to check if first    // character is Capital    static int checkIfStartsWithCapital(String str)    {             if (str.charAt(0) >= 'A' && str.charAt(0)<= 'Z')            return 1;        else            return 0;    }         // Function to check    static void check(String str)    {        if (checkIfStartsWithCapital(str) == 1)            System.out.println("Accepted");        else            System.out.println("Not Accepted");    }         // Driver function    public static void main (String[] args)    {        String str = "GeeksforGeeks";        check(str);             str = "geeksforgeeks";        check(str);    }} // This code is contributed by AnkitRai01
# Python3 program to accept String# starting with Capital letter # Function to check if first# character is Capitaldef checkIfStartsWithCapital(string) :     if (string[0] >= 'A' and string[0] <= 'Z') :        return 1;    else :        return 0; # Function to checkdef check(string) :     if (checkIfStartsWithCapital(string)) :        print("Accepted");    else :        print("Not Accepted"); # Driver functionif __name__ == "__main__" :     string = "GeeksforGeeks";    check(string);     string = "geeksforgeeks";    check(string); # This code is contributed by AnkitRai01
// C# program to accept String// starting with Capital letterusing System; class GFG{         // Function to check if first    // character is Capital    static int checkIfStartsWithCapital(string str)    {             if (str[0] >= 'A' && str[0]<= 'Z')            return 1;        else            return 0;    }         // Function to check    static void check(string str)    {        if (checkIfStartsWithCapital(str) == 1)            Console.WriteLine("Accepted");        else            Console.WriteLine("Not Accepted");    }         // Driver function    public static void Main()    {        string str = "GeeksforGeeks";        check(str);             str = "geeksforgeeks";        check(str);    }} // This code is contributed by AnkitRai01
<script>  // JavaScript program to accept String// starting with Capital letter // Function to check if first// character is Capitalfunction checkIfStartsWithCapital(str){     if (str[0] >= 'A' && str[0] <= 'Z')        return 1;    else        return 0;} // Function to checkfunction check(str){    if (checkIfStartsWithCapital(str))        document.write( "Accepted<br>");    else        document.write( "Not Accepted<br>");} // Driver function var str = "GeeksforGeeks";check(str);str= "geeksforgeeks";check(str);  </script>
Accepted
Not Accepted
 
ankthon
itsok
School Programming
Strings
Strings
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.