How would I answer a question such as “what does the below expression evaluate to”.
"2 + 2 " + 3 + 4;
because I’m having a really hard time on the website practice-it and have tried everything from 2234 to 11 as possible answers.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
In Java if either side of an addition is a string, the non-string operand is converted to a string and the two strings are concatenated. Never will a string be converted to an integer by using addition. Nor will a string containing an integer expression ever be evaluated.
So since addition is left-associative
"2 + 2 " + 3 + 4is parsed as("2 + 2 " + 3) + 4, which will evaluate to"2 + 2 3" + 4, which will in turn evaluate to"2 + 2 34".