• 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

ThreeLetterAcronym

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I am doing homework...again and keep getting 5 errors... I just can't figure out what I am doing wrong.
program:




Compiler errors:

ThreeLetterAcronym.java:20: incompatible types
found : char
required: java.lang.String
oneLtr = name.charAt(0);
^
ThreeLetterAcronym.java:25: cannot find symbol
symbol : method isWhiteSpace(char)
location: class java.lang.Character
if(Character.isWhiteSpace(c))
^
ThreeLetterAcronym.java:26: incompatible types
found : char
required: java.lang.String
if (a <= 1) twoLtr = name.charAt(c+1);
^
ThreeLetterAcronym.java:27: incompatible types
found : int
required: java.lang.String
else if (a <= 2)threeLtr = (c+2);
^
ThreeLetterAcronym.java:28: cannot find symbol
symbol : variable threLtr
location: class ThreeLetterAcronym
name = oneLtr+twoLtr+threLtr;
^
5 errors
 
Bartender
Posts: 10780
71
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Leslie Christ wrote:I am doing homework...again...


Leslie, in future please UseCodeTags (←click). I've added them for you this time to make it easier to to read for others.

Winston

[Edit] I also split the long line 29 into two. Very long lines in code blocks tend to screw up the windowing.
 
Marshal
Posts: 79240
377
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I know the Java™ compiler doesn’t always give comprehensible error messages, but it is spot on here. You have declared those variables as Strings and you are trying to put chars into them. You will either have to change them to char type, or put Strings into them.
You think that c + 2 is a char, but it isn’t. If you look in the Java Language Specification, you find which type it really is. You can get it back to a char by casting, but remember that casting has a higher precedence than addition, so you need ().
You appear to have two spelling errors. Even the tiniest spellling error, like writing Error when you should say error, will throw the compiler. Look in the API documentation for the correct spelling of that method.
 
Campbell Ritchie
Marshal
Posts: 79240
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is something peculiar about those tests, if (a <= 1) ...
What are they supposed to do? Do they actually work?
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic