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

Back to Classroom

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!

An expression is a mixture of literals, operators, variable names, and parentheses used to calculate a value. Please keep in mind that in Java, the expression on the right side of the assignment statement is evaluated first. The expressions will look similar to regular mathematical expressions from math class. Please take a look at the expressions below.

ExpressionsExample.java

package exlcode;
public class ExpressionsExample {
public static int exampleVariableOne = ((7-4) * (-3/-1));
public static void main(String[] args) {
System.out.println(exampleVariableOne);
}
}

Expressions can be written without using any spaces at all, but the use of one or more spaces to visually separate the parts without changing the meaning is useful for the programmer and reader.

Keep in mind the discussion we had previously on division of integers. If the operands are integers, these operators will perform integer arithmetic. If one or both operands are floating points, the operators will perform floating point arithmetic. Any number with a decimal would result in a double or float. For integers, 5/2 results in 2. For floating point, 5.0/2.0 results in 2.5 and 5/2.0 results in 2.5.