• Post Reply Bookmark Topic Watch Topic
  • New Topic

ThreeLetterAcronym  RSS feed

 
Leslie Christ
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • 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.
 
Campbell Ritchie
Marshal
Posts: 56536
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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: 56536
172
  • Mark post as helpful
  • send pies
  • 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?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!