To add two numbers in Java, you can use the +
operator. Here's an example of how to do this:
int x = 5; int y = 7; int sum = x + y;Sourc.www:elautturi.com
This will add the two numbers x
and y
and store the result in the sum
variable.
You can also use the +
operator to concatenate strings. For example:
String s1 = "Hello"; String s2 = "World"; String s3 = s1 + s2;
This will concatenate the two strings and store the result in the s3
variable.