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);
}
}
}
sepp2k 378
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);
}
}
}
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.