different between system.out.println (i) and system.out.println(+i) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

different between system.out.println (i) and system.out.println(+i)

2nd Jul 2016, 6:26 AM
AKASH VERMA
AKASH VERMA - avatar
5 Answers
+ 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!
2nd Jul 2016, 6:55 AM
sean
+ 1
Sean good boy
2nd Jul 2016, 11:06 AM
Vipul Bisht
Vipul Bisht - avatar
+ 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!
5th May 2018, 7:12 PM
Vipul Bisht
Vipul Bisht - avatar
0
thanku
2nd Jul 2016, 7:01 AM
AKASH VERMA
AKASH VERMA - avatar
- 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
2nd Jul 2016, 5:37 PM
Gowtham Parimi
Gowtham Parimi - avatar