Once you click post assignment, learners in the selected class will immediately be able to see and complete this assignment

Back to Classroom

Mixed Expressions

Introduction To Java Course

Engineers From These Top Companies and Universities Trust EXLskills

1M+ Professionals | 100+ Institutions

This is the EXLskills free and open-source Introduction To Java Course. It guides learners via explanation, demonstration, and thorough practice, from no more than a basic understanding of Java, to a moderate level of essential coding proficiency.

Is this course FREE?

Yes, this a 100% free course that you can contribute to on GitHub here!

Mixed expressions are comprised of multiple sub expressions at once. This is not as rampant in Java as it is in advanced algebra courses, but it is essential to remember the rules and use them. Take a look at these two mixed expressions.

MixedExpressionsExample.java

package exlcode;
public class MixedExpressionsExample {
// Keep in mind that 1/3 = 0 because both 1 and 3 are integers
public static double exampleVariableOne = ((1/3+7.5) / 2.5);
public static int exampleVariableTwo = ((7/4 + 2/6) + 4);
public static void main(String[] args) {
System.out.println(exampleVariableOne);
System.out.println(exampleVariableTwo);
}
}

Do either of the results surprise you? Take a look at the details. Remember, if any of the operands are a floating point, the whole arithmetic operation becomes floating point. Also, parenthesis have the highest precedence in the order of operations and must be evaluated first. Let's rearrange the mixed expressions to the correct order of evaluation: