• 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

problem incompatible types...

 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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. ]
 
I've never won anything before. Not even a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic