+ 2
Can someone explain me this code?
public class Program { public static void main(String[] args) { int x = 1; int y = 2; String s = "" + x + y + (x + y); System.out.println(s); } } In this code, I Don't understand the main role of the double quotation marks String s = "" + x + y + (x + y); The double quotation marks convert the numbers to string?
4 odpowiedzi
+ 3
exactly. but first the expression in the brackets will be evaluated first, then everything after the quotation marks will be concatenated to a string.
btw the result of the full statement is: 123
hope that helps. :)
+ 1
if you think my answer was of any help for you, please consider marking it as the best answer. thanks in advance. :)
+ 1
thank you sir :) but I have another doubt, is there another way to convert int to string without using double quotation marks?
0
yes, try it with the Integer wrapper object:
String numStr = Integer.toString(123);