I copied your code and got exactly the output you said you expected to see. How did you run the code?
Please tell us where such code comes from; I am finding it difficult to see the point of that exercise. Maybe seeing the original will help.
Thank you for the link; that tutorial is neither good nor bad, but it doesn't explain things like the “IS‑A” relationship, so I think it probably won't help you,.
Please show how you are running your code, so we can see why you are getting no output.
I see you have greatly improved the code formatting from the tutorial
I agree, I tend to start my studies from the beginning but recently, by that a mean as of today, I think I getting a better handle on the basics. I'm using a website called, w3schools.com and I starting to put the concept together as a result of the Lessons and Exercise format they use.
I personally find it very hard to learn more than one, and certainly more than two languages at once.
Yes, you can learn to do HelloWorld in each, but as things start getting deeper something called Cross-Talk by psychologists kicks in and it becomes very hard to remember which language what is coming to your fingertips as you are typing is actually from.
Just as one example, substring() here in Java takes the first index you DO want and the first index you DON'T want.
In C#, it works like this:
public string Substring (int startIndex, int length);
There are countless other things much harder to remember and much more subtle than this, that can cause you to write code that compiles (well, if the language is compiled that is) but doesn't do what you think at runtime.
Guess who has two thumbs, 33 cows and has looked like an idiot getting very basic things like this wrong on interviews because I had to switch back to a language I had used a fair amount from a different one I had been using a lot recently. This guy.
That doesn't mean you should be monolingual. Once you know a language like it is your first language, it is relatively safe to learn others.
But I find I want one coat of paint to dry before trying to paint over it.
EDIT -- in C++, going past the end of your string in a substr() call is just peachy, it gives you all its got, but in Java:
IndexOutOfBoundsException - if the beginIndex is negative, or endIndex is larger than the length of this String object, or beginIndex is larger than endIndex.
When I was actually a kid, long ago, I did learn many languages at once. That could have been because I was younger and sharper, however, I think it is more because even the simplest languages are like 50 times as big now as the most complex ones I ever looked at, which was probably PL/I...don't let me discourage you if you can actually learn them all at once, but do be aware if attempting to do so is possibly holding you back...
RTFJD (the JavaDocs are your friends!) If you haven't read them in a long time, then RRTFJD (they might have changed!)
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop