This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

toUpper, toLower for chars

 
Anthony Smith
Ranch Hand
Posts: 285
  • 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
  • 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
  • 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