| | |
char = string???
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Apr 2006
Posts: 2
Reputation:
Solved Threads: 0
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.
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
I looked in my textbook but it only shows how to cast ints and doubles.

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
Java Syntax (Toggle Plain Text)
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); }
•
•
Join Date: Apr 2006
Posts: 2
Reputation:
Solved Threads: 0
Nevermind, I found the solution here:
http://www.artima.com/legacy/answers...sages/265.html
http://www.artima.com/legacy/answers...sages/265.html
![]() |
Similar Threads
- Pls help :Find first non-repeated char in a string (C++)
- Comparing two letters in one string with another char string? (C)
Other Threads in the Java Forum
- Previous Thread: Netbeans demo projects
- Next Thread: adding an image to a java code
| Thread Tools | Search this Thread |
Tag cloud for Java
actionlistener android api apple applet application apps arguments array arrays automation balls binary bluetooth card chat class classes client code component consumer database draw eclipse ee error event exception fractal free game gameprogramming gis givemetehcodez graphics gui helpwithhomework html ide image input integer j2me j2seprojects java javaprojects jmf jni jpanel julia jvm key linux list loop machine map method methods migrate mobile myaggfun netbeans newbie nextline nls notdisplaying number oracle output print problem program programming project recursion recursive scanner screen security server set size sms socket sort spamblocker sql sqlite string sun swing terminal test threads time tree trolltech windows






