Im trying to cast a char to a string, but if i just define equality, the complier says incompatible types.
I looked in my textbook but it only shows how to cast ints and doubles.:sad:
I have to write a class that takes a char and a String. It then searches the string for the char and returns a boolean.
Im useing a scanner to do this, and it will only accept a string, not a char. Maybe I'm going about this all wrong, if so, please point me in the right direction.

Thanks
Colin

public static boolean isThere(char sreachChar, String stringToSreach)
  {
      String stringToSreachLower = stringToSreach.toLowerCase();
      String stringToSreachUpper = stringToSreach.toUpperCase();
      
      String sreachString=sreachChar;//WTF???
      
      Scanner stringScannerLower = new Scanner(stringToSreachLower);
      Scanner stringScannerUpper = new Scanner(stringToSreachUpper);
      
      String text = key.readWord();//inputs up to white space
                    key.readLine();//Clear input buffer
      
      if(stringScannerLower.findInLine(sreachString) == sreachString | stringScannerUpper.findInLine(sreachString) == sreachString)
      {
          return(true);
      }
      else
          return(false);
  }

Recommended Answers

All 2 Replies

this is Java, not C.
A String isn't a char so you can't cast one to the other.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.