Paweł Baczyński wrote:What is the output?
public class Main {
public static void main(String...args) {
https://coderanch.com/t/658698/ocajp/certification/true-equal-false
for(int i = 0; i < 10; i++) {
System.out.println("Hello " + +i);
}
}
}
Saed Hussein wrote:
and it will display:
Hello 0
Hello 1
Hello 2
Hello 3
Hello 4
Hello 5
Hello 6
Hello 7
Hello 8
Hello 9
be aware if you preincrement i and change your for loop body code like this result will be different and the code will display at round 0;
Are you sure you mean ++1? That will surely print Hello1 ten times. You probably meant ++i.Saed Hussein wrote:. . . result will be different and the code will display at round 0;
And surely the numbers would count up not down as I had it.Roel De Nijs wrote:. . . Pretty sure Hello10 won't be part of the output...
Good one PawelPaweł Baczyński wrote:What is the output?
Campbell Ritchie wrote:
Are you sure you mean ++1? That will surely print Hello1 ten times. You probably meant ++i.Saed Hussein wrote:. . . result will be different and the code will display at round 0;
Campbell Ritchie wrote:Now, I have seen that sort of puzzle before, but does anybody here know why it will compile and run apparently without errors?
Saed Hussein wrote:may be I don't have any idea for puzzlers.
Roel De Nijs wrote:
Saed Hussein wrote:may be I don't have any idea for puzzlers.
That's the beauty of this Java puzzler, and I do know it looks (and sounds) very strange but it's really true: you don't need to comment the url out to successfully compile the code snippet So the code from the original post will compile without any errors
And whoever getting ready for OCA exam, what will be the output now? Beware, some misdirection techniques has been used
Ramya Subraamanian wrote:the varargs syntax in the main method is wrong so the code doesnt compile
Ramya Subraamanian wrote:I guess if you modify it as above the Output will be the normal for a loop Hello 0 to Hello 9.
Ramya Subraamanian wrote:all the + in this are all concatenation operators, it still works as if you add another +
Ramya Subraamanian wrote:this snippet will give output of 100 and 101 - in first statement it is concatenation and pre-increment in the second.
Ramya Subraamanian wrote:Is it a Unary plus operator below as well ?
Ramya Subraamanian wrote:why does this gives me a output of concatenation : your R is -->100100, your R is -->200200
Campbell Ritchie wrote:Which means I can go back to the first post in this thread where it was split from an earlier thread and warn you not to write
\u000a
inside the URL.
We don't have time for this. We've gotta save the moon! Or check this out:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
|