Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

how to make alphabets uppercase without using function

  Asked By: Robert    Date: Nov 19    Category: Java    Views: 1668

Please tell me how to change chars to uppercase without using touppercase
function.explain with code plz.



2 Answers Found

Answer #1    Answered By: Hayden Evans     Answered On: Nov 19

class Testing {
public static void main(String[] args) {
char c1 = 'a', c2;
c2 = (char) ( c1 - ('a' - 'A'));

String s1 = "abc", s2 = "";
for (int i=0; i<s1.length(); i++) {
s2 = s2 + (char) ( s1.charAt(i) - ('a' - 'A') );
System.out.println( c2 + " " + s2);
do add other code  to check that the char you are converting
is between 'a' to 'z'.

Answer #2    Answered By: Sairah Hashmi     Answered On: Nov 19

Another approach would be to have an array of char ("char[65536]
Uppercase;") which contains all characters supported on your
platform; then add the following:
Uppercase ['a'] = 'A';
Uppercase ['b'] = 'B';
Uppercase ['z'] = 'Z';

Then, whenever you want to substitute a character by its uppercase
version, use
Uppercase [ch]
instead of ch.

I know, looks ugly, but according to OP I wanted to avoid calling any
functions, such as toupper().

Didn't find what you were looking for? Find more on how to make alphabets uppercase without using function Or get search suggestion and latest updates.