codescracker


java

Java Program to Convert Lowercase to Uppercase



« Previous Program Next Program »


Convert Lowercase to Uppercase

To convert/change lowercase string/character to uppercase string/character in Java programming, you have to use ASCII value to convert the lowercase character into uppercase character as shown in the following first program. And the second program, uses the method toUpperCase() to convert lowercase string into uppercase string.

Convert Character from Lowercase to Uppercase

To convert the lowercase character into uppercase character in Java Programming, you have to ask to the user to enter the character, now start converting lowercase character to uppercase character by using ASCII values. To convert lowercase to uppercase, just minus 32 from the character since the ASCII value of 'A' is 65 and the ASCII value of 'a' is 97, so 97-65=32. So to convert character from lowercase to uppercase just minus 32 from the character.

Java Programming Code to Convert Lowercase Character to Uppercase

Following Java Program ask to the user to enter a character in lowercase to convert it into uppercase, then display the result on the screen:

/* Java Program Example - Convert Lowercase Character to Uppercase */
		
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 Lowercase : ");
        ch = scan.next().charAt(0);
		
        temp = (int) ch;
        temp = temp - 32;
        ch = (char) temp;
		
        System.out.print("Equivalent Character in Uppercase = " +ch);
    }
}

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

Java Program convert lowercase character to uppercase

Convert String from Lowercase to Uppercase

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

Java Programming Code to Convert Lowercase String to Uppercase

Following Java program uses toUpperCase() method to convert the string from lowercase to uppercase :

/* Java Program Example - Convert Lowercase String to Uppercase */
		
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 Lowercase : ");
        strUpper = scan.nextLine();
        
        strLower = strUpper.toUpperCase();
        System.out.print("Equivalent Word/Name in Uppercase : " +strLower);
    }
}

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

Java Program convert lowercase string to uppercase

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