Convert Unique Uppercase to Lowercase Letter: The “Uppercase to Lowercase Conversion” Java program addresses the task of converting uppercase letters within a given string into their corresponding lowercase forms. By processing the provided input string, the program produces an output string where all uppercase letters have been transformed to lowercase while preserving the positions and characters of the remaining text.
For instance, when presented with the input string “Hello Interview Is Going On Now,” the java programming language executes the conversion and yields the output string “hello interview is going on now.” This program is particularly useful in scenarios where uniform letter casing is required for consistency and ease of further processing.
Through this program, learners become acquainted with the essentials of string manipulation, character iteration, and conditional transformations in Java programming. This foundational exercise introduces beginners to fundamental concepts used in text processing and prepares them for more complex tasks involving string handling and data transformation.
Convert Unique Uppercase to Lowercase Letter Program
This Java program, InterviewPrograms_100, aims to convert uppercase letters within a given string to their corresponding lowercase forms. It does so by iteratively processing each character in the input string and transforming uppercase characters to lowercase while leaving the rest of the string unchanged.
package com.softwaretestingo.interviewprograms; public class InterviewPrograms_100 { /* * Given a string and return the string after replacing every uppercase letter * with the same lowercase letter. Input : s = "Hello Interview Is Going On Now" * Output : "hello interview is going on now" */ //This Questions Asked in Cigniti technologies public static void main(String[] args) { String s= "Hello Interview Is Going On Now"; char[]c = s.toCharArray(); for(int i=0;i<c.length;++i ) { if(c[i]>=65 && c[i]<=90) { c[i] = (char) (c[i] + 32); } } System.out.println("After Converting: "+String.valueOf(c)); } }
Output:
Original String: Hello Interview Is Going On Now After Converting: hello interview is going on now
Here’s a concise step-by-step explanation suitable for Java beginners:
- Program Objective: The program’s goal is to transform an input string, such as “Hello Interview Is Going On Now”, into an output string where all uppercase letters are converted to lowercase. For example, the input would yield the output “hello interview is going on now”.
- Character Array: The program first converts the input string into a character array named c using the toCharArray() method. This facilitates individual character manipulation.
- Iterative Conversion Loop: The program employs a loop that iterates through each character in the character array c.
- Conditional Transformation: Within the loop, a conditional statement checks whether the current character’s ASCII value falls within the uppercase letter range (between 65 and 90). If true, the character is converted to lowercase using the ASCII conversion logic (c[i] + 32).
- Printing Results: After the loop, the program prints the modified character array as a string using String.valueOf(c).
- Main Method: The main method initializes the program, defines the example input string, and processes it to achieve the desired transformation. The converted string is then printed as the output.
Through this program, beginners learn about character manipulation, ASCII values, and basic iterative processing of strings. It illustrates the process of converting characters between different cases and showcases how simple programming constructs can be used to achieve significant text transformations.
Leave a Reply