Ask Question
23 June, 09:49

Where is the error in this code sequence?

String s1 = "Hello";

String s2 = "ello";

String s = s1-s2;

java programming

+3
Answers (1)
  1. 23 June, 10:56
    0
    There is an error in "String s=s1-s2 ";

    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.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Where is the error in this code sequence? String s1 = "Hello"; String s2 = "ello"; String s = s1-s2; java programming ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers