Comp 110 Assignment

The assignment operator is denoted as "=" or the equal sign. Note that in math class, we described the = sign as "equals", but in Java we describe this as assignment. 

For example, this is assigning a value to a variable:

double foo = 2.354;

This is assigning the value 2.345 to foo. 


Practice problems:

Which "if" statement is syntactically incorrect?

int i = 4;
int y = 4;

if(y == i){    // 1.)
//do something
}

if(y=i){      //  2.)
//do something
}

Answer:

Here the second "if" statement is incorrect. This is because the value between the parentheses needs to be a boolean value, not an assignment (hint: y == i results in a true or false value)