Convert the given string into uppercase in Java

The string in converts all characters of the string into upper case letter. The string to be any length and calculate its length. scan string character by character and keep checking the index. If a character in an index is in lower case, then subtract 32 to convert it in upper case.

Source Code

public class uppercase {
    public static void main(String args[]) {
        //Program to Convert string to Uppercase
        StringBuilder a = new StringBuilder("abc");
        System.out.println("Original Input : "+a);
        for(int i=0;i<a.length();i++)//97-122
            if (a.charAt(i) >= 97 && a.charAt(i) <= 122) {
                int c=(int)a.charAt(i)-32;//97-32=65  98-32=66  99-32=67
        System.out.println("Uppercase Output: "+a);


Original Input    : abc
Uppercase Output  : ABC
To download raw file Click Here

Basic Programs