This article is created to cover a program in Java that converts uppercase character or string to its equivalent lowercase version with and without using string function. Here are the list of programs covered in this article: Show
The string function, I'm talking about, is toLowerCase(). Note - ASCII values of A-Z are 65-90. And ASCII values of a-z are 97-122. Note - ASCII value of 'a' is 97, whereas the ASCII value of 'A' is 65. Means the ASCII value of lowercase character to its equivalent uppercase, is 32 more. Therefore, adding 32 to the ASCII value of an uppercase character, becomes the ASCII value of its equivalent lowercase character. Uppercase Character to Lowercase in Java using ASCIIThe question is, write a Java program to convert an uppercase character to its equivalent lowercase character using ASCII value of the character. The character must be received by user at run-time of the program. The program given below is its answer: import java.util.Scanner; public class CodesCracker { public static void main(String[] args) { char chUpper, chLower; int ascii; Scanner scan = new Scanner(System.in); System.out.print("Enter a Character in Uppercase: "); chUpper = scan.next().charAt(0); ascii = chUpper; ascii = ascii + 32; chLower = (char)ascii; System.out.println("\nEquivalent Character in Lowercase = " +chLower); } } The snapshot given below shows the sample output produced by above Java program. This is the initial/first output:
Updated on 09-Mar-2021 08:57:45 |