• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Find one char in a String ? ? ?

 
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 348
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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));
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic