File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toUpper, toLower for chars

 
Anthony Smith
Ranch Hand
Posts: 285
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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];
else
{
char new_letter = letters[(int)x];
new_letter.toLowerCase('k');
return new_letter;
}
}

The toLowerCse will not work. Char cannot be de-refernced it says
 
Bill Krieger
Ranch Hand
Posts: 53
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 88
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic