Q: Two if statements, only one works I have two if statements in my code, but when both are true, it only only makes the second if. How should I write it?
String s1 = editTextl.getText().toString();
double d = 0;

if (s1.contains("H")) {
    d = + H;     //H is double with value of 1
}
if (s1.contains("O")) {
    d = + O;     //O is double with value of 16   
}

TextView.setText(" " + getString(R.string.vysledek) + " " + d);

When I type HO in EditText, TextView should return value of 17, but it returns only 16. Why?

A: You need to write it as follows, replacing = + with +=:
if (s1.contains("H")) {
    d += H;
}

if (s1.contains("O")) {
   d += O;
}

+= is a so-called compound assignment operator. It adds the right operand to the left operand.
The inverse, =+, just assigns the right operand to the left operand and is equivalent to a simple assignment using =. The unary + operator is ignored.

A: Replace = + with +=.
= is an assignment operator, + is an unary plus operator that basically does nothing. So you're assigning a new value to the variable.
+= is "add to the current value of left hand side".

A:     double d = 0;

    if (s1.contains("H")) {

        d += 1; // H is double with value of 1

    }

    if (s1.contains("O")) {

        d += 16; // O is double with value of 16

    }


A: Change the = + assignments to += assignments - d = + H is really just interpreted by the compiler as d = +H. You're not actually adding H to d, you're just setting d = H.

A: Replace d = + H with   d += H and d = + O with d += O 
