There are two compilation errors in your code, otherwise it works fine. The first one is a common beginner error (2nd line, not including comments) that you should get used to finding and resolving as it won't be the last time you do it. The second is a careless typo (2nd to last line not including comments). Slow down and pay attention when you're typing - you'll save yourself time later.
What does the compiler tell you is wrong and where (what line) is it telling you that the problem is on? Can you see anything that isn't as it should be? If you're really struggling, try commenting out complete statements or blocks of statements and see if the compilation error goes away. If, after trying hard to work it out, you're really stuck then post your code fragment on JavaRanch as you have done but be specific about what your problem is, i.e. my code won't compile: here's the error I get, here's my code, this is what I've tried.
If you help us we'll help you. I tidied up your code a bit but I've decided not to give it to you as I don't think it'll help you learn at present.
Well, this is what I mean by not posting until you really need help. I've wasted my time trying to help you with something you weren't really stuck with. What do you think the new error message means? How do you think it might be possible to get round it? If you can't compare Strings, what could you compare? If it makes your head hurt then I know the feeling but the effort is worth it.
As I recommended to someone else in another thread I think you'd benefit from going back over some of the basics of learning Java. Do you have course notes or a tutorial or a good book or something? Take things in small steps and grasp the basic concepts. Your question is a basic one even for the beginner forum.
I don't want to discourage you; I'm just trying to save you some pain.
Oh thank you so much for helping me out. I am very excited you say it works, but not so excited I cant get it to work. I am trying to find those problems you were telling me about but i dont see it. im gunna keep looking some more, but in the mean time did you see the part above about the two errors i was getting? thanks again for all your help ill keep looking for those two mistakes.
You've fixed the mistakes I mentioned (I think) that's why you're seeing the other errors. Here's a useful tip that you may not be aware of: always fix the first error in the list that the compiler comes up with first. Sometimes if you fix the first error it makes all the other ones go away. Cool, huh? If you try and fix the second or subsequent errors without fixing the first you may well be wasting your time as they may not be errors at all! Always, always, ALWAYS fix the first error first.
im really sorry i made you waste your time...i really dont understand why i am getting the errors and i have three books and class notes but for some stupid reason i cannot figure it out and can't see it and that is why i was asking for help. i guess ill just keep reading and hope i get it. again thank you for the help and i am sorry.
By the way, the reason that my little piece of test code works fine is that I use the right data type for the age. Here it is, see if this helps you:
With regard to your books, etc., my advice is to start at the beginning and make sure you understand each bit as you go along. Once you've done that, go through it a second time and it'll all be much clearer. The basics are really important. Without a good grasp of the basic concepts you're really going to struggle with the trickier stuff. It's time well spent.
ok i am getting an error saying ; is expected and is pointing to the if and else statements...i know i should know this but does have to do with the way i am writing the message? or with the whole string message together?
I can't see what you're doing but there's nothing wrong with the code you posted above. The compiler normally points you to exactly where it is expecting a semicolon. My advice is to stick a semicolon there (usually the end of a line) and see if it compiles. If not, or if it compiles but doesn't behave as expected try commenting out the lines of code either side to see if that helps. You may also find it easier, as a beginner, to get into the habit of coding your if/else statements as follows:
Putting the curly brackets (braces) in can help save you some pain further down the line when you want to add code to the if statement. I don't know if that's your problem. Probably not. You've probably just left the ; off the end of your message string initialisation (total guess).
Hey Jules!! Thank you so much for all the help today! You are awesome. I have the program working like a champ!! Thank you soooo much. I am sure I will be back on here in the next few days for more help, but I now know how to ask for it and make everything a little less confusing. Thanks again you helped me so much!
What's a year in metric? Do you know this metric stuff tiny ad?
Free, earth friendly heat - from the CodeRanch trailboss