class stringadd{
public static void main(String ar[]){
String a="10";
string b="20";
System.out.println(a+b);
}
}
................................
how to print 30 instead of 1020
.........................................
Printable View
class stringadd{
public static void main(String ar[]){
String a="10";
string b="20";
System.out.println(a+b);
}
}
................................
how to print 30 instead of 1020
.........................................
Integer.parseInt(a) + .....
One of the confusing things for beginners. The meaning of the + operator depends on where/how it's used. When used with primiitives like int or long it means: arithmetic sum ie add the values of the two numbers and return their sum.
When used between Strings, it means: concatenate the two strings and return a new String with the 2 strings concatentated. That is what you observed.