A PHP Error was encountered

Severity: 8192

Message: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated

Filename: libraries/Filtered_db.php

Line Number: 23

Lowercase to uppercase conversion without using any library function in Java
Q:

Lowercase to uppercase conversion without using any library function in Java

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)

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now