codescracker


java

Java Program to Convert Uppercase to Lowercase



« Previous Program Next Program »


Convert Uppercase to Lowercase

To convert or change uppercase string or character to lowercase string or character in Java Programming, use the ASCII values of character to convert any character from uppercase to lowercase as shown in the first program. And the second program uses the method toLowerCase() to convert string from uppercase to lowercase.

Convert Character from Uppercase to Lowercase

To convert uppercase character to lowercase character, you have to ask to the user to enter the character in uppercase to convert it into lowercase to display the equivalent character in lowercase. To change uppercase character into lowercase character, just add 32 in the character to convert it into lowercase. Since ASCII value of A is 65 and ASCII value of a is 97, so 65+32 = 97 = a = equivalent value of A in lowercase i.e., a

Java Programming Code to Convert Uppercase Character to Lowercase

The following Java Program ask the user to enter a character in uppercase to convert it into lowercase, then display the result on the screen. Since ASCII value of A is 65 and ASCII value of a is 97. So to convert a character from uppercase to lowercase, we have to add (97-65) i.e., 32 to get the ASCII value of the character in lowercase. Then print it on the screen :

/* Java Program Example - Convert Uppercase Character to Lowercase */
		
import java.util.Scanner;

public class JavaProgram
{
    public static void main(String[] input)
    {
        char ch;
        int temp;
        Scanner scan = new Scanner(System.in);
        
        System.out.print("Enter a Character in Uppercase : ");
        ch = scan.next().charAt(0);
		
        temp = (int) ch;
        temp = temp + 32;
        ch = (char) temp;
		
        System.out.print("Equivalent Character in Lowercase = " + ch);
    }
}

When the above Java Program is compile and executed, it will produce the following output:

Java Program convert uppercase character lowercase

Convert String from Uppercase to Lowercase

To convert any string from uppercase to lowercase, use the method toLowerCase() to convert all the uppercase character present in the string to lowercase.

Java Programming Code to Convert Uppercase String to Lowercase

The following Java Program ask to the user to enter a string like first name in uppercase to change it into lowercase, then display the result on the screen:

/* Java Program Example - Convert Uppercase String to Lowercase */
		
import java.util.Scanner;

public class JavaProgram
{
    public static void main(String[] input)
    {
        String strUpper, strLower;
        Scanner scan = new Scanner(System.in);
        
        System.out.print("Enter one word/name in Uppercase : ");
        strUpper = scan.nextLine();
        
        strLower = strUpper.toLowerCase();
        System.out.print("Equivalent Word/Name in Lowercase : " + strLower);
    }
}

When the above Java Program is compile and executed, it will produce the following output:

uppercase to lowercase conversion in java

Same Program in Other Languages

You may also like to learn and practice the same program in other popular programming languages:


« Previous Program Next Program »



Tools
Calculator

Quick Links
Signup - Login - Give Online Test