Q:

Lowercase to uppercase 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 lowercase to uppercase.

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 lowercase to uppercase conversion

// Lowercase to uppercase conversion without using 
// any library function in Java

public class Main {
    static String LowerToUpper(String s) {
        String result = "";
        char ch = ' ';
        for (int i = 0; i < s.length(); i++) {
            
            //check valid alphabet and it is in lowercase
            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(LowerToUpper("IncludeHelp.com"));
        System.out.println(LowerToUpper("www.example.com"));
        System.out.println(LowerToUpper("123abcd@9081"));
        System.out.println(LowerToUpper("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
Uppercase to lowercase conversion without using an... >>
<< Java program to concatenate two strings without us...