+ 1
different between system.out.println (i) and system.out.println(+i)
5 ответов
+ 12
Hey akash, there is only a small technical difference between your i and +i. when you println your i variable, it will simply display your int, double, string or char variable that you applied to the variable i. The "+i" is going to simply print out the exact same thing as i would do, because in Java outside of quotation marks (" ") a + symbol is read as an "and" or "combine." so for instance if your i variable was String i = "Hello" and let's say you had a variable k that was String k = "Akash" and you did System.out.println (i+k) then the return you would receive is HelloAkash. Also yes, you read it right that there is no spaces, that's because java only reads spaces if you input it like this System.out.println (i+" "+k) which would then be Hello Akash. Now let's move to numericals. if i was int i = 1 and k was int k = 2, then System.out.println (i+k) would return you 3 because it "combines" or adds numerical numbers. hope this helps and please upvote!
+ 1
Sean good boy
+ 1
see it will return either error or will give the same result as the first one. But if you give some string in front then the + sign tends to concat the given number or string with the before + sign specified string.Hope you liked my answer then give a upvote to me.
Thank you!
0
thanku
- 7
In the first case only the value of i is printed without any change, where as in the second case the value of i is incremented by 1 and then it is printed. There is another possible case System.out.println(i++)...here original i value is printed and then it is incremented by 1 and stored in the computer