| Author |
problem incompatible types...
|
Brian Walsh
Greenhorn
Joined: Feb 06, 2002
Posts: 17
|
|
I was having problems with incompatible types on a string to be read. I want to read a string and each letter be printed on a seperate line...right now I am working on this line.... here is the error when compiling.
A:\Chapter 3\Bench\StringRead.java:22: incompatible types found : char required: java.lang.String place = Character.toLowerCase(sentence.charAt(i)); ^ 1 error Tool completed with exit code 1
I understand the basics of objects, but I am still working on how to use the api right. Could anyone point me out to a tutorial that would help me? Thank you very much. Here is the entirety of the program still in progress....
import cs1.Keyboard; public class StringRead { public static void main (String[] args) { String num, place, sentence; int i , letter; System.out.println ("Please put in a string of letters or a sentence..."); sentence = Keyboard.readString(); for (i = 0; i < sentence.length();++ i) { place = Character.toLowerCase(sentence.charAt(i)); } } }
Thanks again for your help and time.... -Calv1n
|
-Thanks in Advance
|
 |
Tim B.
Greenhorn
Joined: Feb 03, 2003
Posts: 10
|
|
Hi Brian, The error occurs because you're trying to assign a 'char' to a 'String' object. Your 'place' variable is declared as a String object, but the static 'toLowerCase()' method of the 'Character' class, returns a 'char'. A solution to this problem might be the following lines of code: Or if you like to do everything on one line: Hope this helped you out a bit. Greetings, Tim [ February 03, 2003: Message edited by: Tim B. ]
|
 |
 |
|
|
subject: problem incompatible types...
|
|
|