Q:

C# program to change the case of entered character

belongs to collection: C# Basic Programs | basics

0

C# program to change the case of entered character

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Program:

The source code to change the case of entered character is given below. The given program is compiled and executed successfully on Microsoft Visual Studio.

//C# program to change the case of entered character.

using System;

class CaseDemo
{
    static void Main(string[] args)
    {
        char ch;
        
        Console.Write("Enter a character : ");
        ch = Convert.ToChar(Console.ReadLine());
        
        if (ch >= 65 && ch <= 90)
        {
            Console.WriteLine("Convert Character '"+ch+"' into : '"+char.ToLower(ch)+"'");
        }
        else if (ch >= 97 && ch <= 122)
        {
            Console.WriteLine("Convert Character '" + ch + "' into : '" + char.ToUpper(ch) + "'");
        }
    }
}

Output:

Enter a character : k
Convert Character 'k' into : 'K'
Press any key to continue . . .

Explanation:

In the above program, we created a class CaseDemo that contains the Main() method. In the Main() method, we read a character from the keyboard.

if (ch >= 65 && ch <= 90)
{
    Console.WriteLine("Convert Character '"+ch+"' into : '"+char.ToLower(ch)+"'");
}

In the above code, we checked entered character is an uppercase character or not. Because the ASCII value of 'A' is 65 and the ASCII value of 'Z' is 90. Then here we converted the entered character into lowercase character.

else if (ch >= 97 && ch <= 122)
{
    Console.WriteLine("Convert Character '" + ch + "' into : '" + char.ToUpper(ch) + "'");
}

In the above code, we checked entered character is a lowercase character or not. Because the ASCII value of 'a' is 97 and the ASCII value of 'z' is 122. Then here we converted the entered character into uppercase character.

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

C# Basic Programs | basics

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
C# program to convert entered days into years, wee... >>
<< C# program to create gray code...