|
when you concatenate using a string and some other variables, all the values are concatenated together, so if a = 5 and b = 6, the output of the code:
System.out.println("The values are: " + a + b);
would be: The values are: 56
That is because it converts the primitives a and b to strings and concatenates them together. If u want a and b to be added, this will to it:
System.out.println("The values are: " + (a + b));
This is becos parenthesis takes precedence anywhere!
But if u want the two values to be displayed 'as is', you have to put a space btw them i.e
System.out.println("The values are: " + a + " " + b);
Take care!
|