Upper Case without using API in Java

In this example, We will show you about, Converting String to Upper Case without using API in Java. The example were tested and output is shared.

#1 Example Program

package com.dineshkrish.string;
/**
* 
* @author Dinesh Krishnan
*
*/
public class UpperCaseExample {
public static void main(String[] args) {
String strValue = "dinesh krishnan";
String upperCase = "";
char[] c = strValue.toCharArray();
for (int i = 0; i < c.length; i++) {
int ascii = c[i];
if ((ascii >= 97) && (ascii <= 123)) {
upperCase = upperCase + "" + (char) (c[i] - 32) + "";
} else {
upperCase = upperCase + "" + (c[i]) + "";
}
}
// Printing the result
System.out.println(upperCase);
}
}

#2 Output

DINESH KRISHNAN

References

1. Java String JavaDocs

Tags:

No responses yet

Leave a Reply

Your email address will not be published. Required fields are marked *