[UNANSWERED ]Precedence | SoloLearn: Learn to code for FREE!

+1

[UNANSWERED ]Precedence

Please give some material on operators' precedence or explain it. How does basic arithmetic rules differ from program ones? Like the arithmetic rule - the order of summands dont change the result but in Java string + int +int causes first concat, and due to this the second is also concat and the whole expression is a string. Seems that multiplication and modulus have different precedence.

4/18/2017 7:36:47 AM

Alex Rassadin

4 Answers

New Answer

+2

The plus(+) operator is used for string concatenation, along with its natural role (addition). Its behaviour is defined as its position in the statement, example: alert(5+6+"hello"+5+6); The first plus sign will act naturally as addition operator, because its position is between 2 numbers, and the result is 11; while the other + signs will append Everything after that resulting of string: 11hello56

+2

I can't understand exactly what do you want. You have to search some tutorials, like this: https://www.javatpoint.com/operators-in-java

0

@$Baalbek$ This case was brought as an example. I want to know similar occasions which are abnormal in simple arithmetics.

0

Arithmetics: the order of operands when adding or subtracting is not important :"string"+10+20 according to arithmetical rules is string30 Coding : "string" +10+20 results in string1020 I want to know more of such stuff.