0
public class secenek {
      public static void main(String[] args) 
      {
    int option=0;
    int a,b;
    a=5;
    b=7;
    if (option==0){
        System.out.println("A+B= "+a+b);

    }


}
}
2
Contributors
1
Reply
8
Views
5 Years
Discussion Span
Last Post by sepp2k
1

The + operator associates left to right, so when you write "A+B= "+a+b that's parsed as ("A+B= "+a)+b. "A+B= "+5 is "A+B= 5" and "A+B= 5"+7 is "A+B= 57", so that's the result. You need to add 5 to 7 first and then add the result to the string. To do that put 5+7 in parentheses.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.