Ask Question

Where is the error in this code sequence?

String s1 = "Hello";

String s2 = "ello";

String s = s1-s2;

java programming

+4
Answers (1)
  1. 20 August, 11:13
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers