This week's giveaway is in the EJB and other Java EE Technologies forum. We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line! See this thread for details.
Pete is correct, that's totally wrong in C, too. The difference is that in C, nothing automatically lets you know that you've stomped on the data past the end of your array. So it might just work OK, or you might crash (the larger the program, the more likely this will eventually cause a crash.) Java reports the problem without letting it happen -- Java is much "safer" than C in that way.
In any case, in C, Java, C++, or any similar language, the elements of a ten-item array are numbered 0 through 9, not 1 through 10. If you want to print "enter element 1" for the first element, then use
Actually this is a very good example of the need for such an out of bounds error message, sounds like Kunagu has been writting bugged C code for some time and not realised it. May have led to some interesting logic errors.
Joined: Apr 13, 2010
ok guys... Thank you for your valuable responses....
When there are lot of advantages compared with other languages we have to adjust with java.. I will use the following statement