Java Program To Convert Character Cases

Write Java program to convert character cases

// WAP  to convert a character from upper to lower and lower to upper case

import java.util.Scanner;
public class CharacterCase
{
    public static void main(String[] args) 
    {
        Scanner sc = new Scanner(System.in);
        
        // convert in Lower case
        System.out.println("Enter character in upper case :-->");
        char upper = sc.next().charAt(0);

        int ascii = upper + 32;
        System.out.println("Lower case of "+upper+" is : "+(char)ascii);

        // convert in Upper case
        System.out.println("Enter character in lower case :-->");
        char lower = sc.next().charAt(0);

        ascii = lower - 32;

        System.out.println("Upper case of "+lower+" is : "+(char)ascii);
    }
}

Output:


<< Previous | Next >>


Leave a Reply

Your email address will not be published.