81.7k views
1 vote
Where is the error in this code sequence?

String s1 = "Hello";

String s2 = "ello";

String s = s1-s2;

java programming

User Doinghun
by
5.6k points

1 Answer

5 votes

Answer:

There is an error in "String s=s1-s2 ";

Step-by-step explanation:

In java programming, we can subtract subtract two strings variable with "-" operator.Java programming does not support an overload of the '-' operator.In java, we can use only "+" operator to append two strings variable.There is no such method to subtract strings in java.Therefore in the given code String s=s1-s2 will give an "bad operand type" error because we can not subtract one string variable from the second string variable.

User Zoccadoum
by
6.1k points