Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Find one char in a String ? ? ?

 
Douglas Braxton
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
PROBLEM: String s (of indeterminate length) is passed to the method searchString(), the user is prompted to enter a one character search argument name s1. Object of the exercise is to count the number of times
s1 occurs within s, regardless of case h = H, H = h, as it were.
CAN ANYONE FIGURE OUT WHERE I AM GOING WRONG.
THIS IS THE METHOD CALL

THIS IS THE METHOD

COMPILER MESSAGES
MyStrings.java [154:1] char cannot be dereferenced
char s2 = s1.charAt( 0 ).toLowerCase( ) ;
^
MyStrings.java [162:1] char cannot be dereferenced
s2 = ( s1.charAt( 0 ).toUpperCase( ) );
^
2 errors
Errors compiling MyStrings.
THANK YOU
doug
 
chi Lin
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
toLowerCase() & toUpperCase() can not be used on char returned
by s1.charAt(0);
try
Character.toUpperCase(s1.charAt(0));
Character.toLowerCase(s1.charAt(0));
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic