Q:

Uppercase to lowercase conversion without using any library function in Java

belongs to collection: Java String Programs

0

Given a string and we have to convert it from uppercase to lowercase.

Examples:

    Input:
    IncludeHelp.com
    Output:
    includehelp.com

    Input:
    123ABCD@9081
    Output:
    123abcd@9081

 

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Java code for uppercase to lowercase conversion

// Uppercase to lowercase conversion without using 
// any library function in Java

public class Main {
    static String UpperToLower(String s) {
        String result = "";
        char ch = ' ';
        for (int i = 0; i < s.length(); i++) {
            
            //check valid alphabet and it is in Uppercase
            if (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z') {
                ch = (char)(s.charAt(i) + 32);
            }
            //else keep the same alphabet or any character
            else {
                ch = (char)(s.charAt(i));
            }
            
            result += ch; // concatenation, append c to result
        }
        return result;
    }

    public static void main(String[] args) {
        System.out.println(UpperToLower("IncludeHelp.com"));
        System.out.println(UpperToLower("www.example.com"));
        System.out.println(UpperToLower("123ABCD@9081"));
        System.out.println(UpperToLower("OKAY@123"));        
    }
}

Output

includehelp.com
www.example.com
123abcd@9081
okay@123

 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Java String Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
Comparing Strings with equals() and compareTo() me... >>
<< Lowercase to uppercase conversion without using an...