File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes toUpper, toLower for chars Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "toUpper, toLower for chars" Watch "toUpper, toLower for chars" New topic

toUpper, toLower for chars

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
public static char letter(boolean isUpper)

char[] letters = {'A', 'B', 'C', 'D', 'E', 'F', 'G',
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R' ,'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
double x = Math.random()*25;
if (isUpper==true)
return letters[(int)x];
char new_letter = letters[(int)x];
return new_letter;

The toLowerCse will not work. Char cannot be de-refernced it says
Bill Krieger
Ranch Hand

Joined: Sep 27, 2001
Posts: 53
The variable 'new_letter' is a char primative. Primative values are not objects, they have no member variables or methods. Perhaps you meant to us the Character wrapper class? Perhaps...
new_letter = Character.toLowerCase( letters[(int)x] );
Colin Kenworthy
Ranch Hand

Joined: Aug 06, 2001
Posts: 88
Learn the difference between char and Character.
Learn the difference between a primitive type and an Object.
...then you should understand what's going on.
I agree. Here's the link:
subject: toUpper, toLower for chars
It's not a secret anymore!