Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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));
 
Wanna see my flashlight? How about this tiny ad?
We need your help - Coderanch server fundraiser
https://coderanch.com/t/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic