Arithmetic expressions


We already know that you can set the value of a variable using the input staememt.

The input statement is used in cases where the value is set by the user during program execution.

But very often we need to set a new value for a variable, calculating it according to a certain formula. In this case, the assignment expression will help us

The general form of the assignment expression is as follows:
<variable>=<expression>;

The assignment expression works as follows:
1. First, the expression to the right of the assignment sign is calculated
2. The received value of the expression is saved (they say "assigned") in the variable standing to the left of the assignment sign. In this case, the old value of the variable is erased.

For example, if we need to set the variable c to a value two times the value of the variable b, then we will have to write it like this:
с=2*b;

Remember that in programming you cannot omit the multiplication signs in an expression. Otherwise, the computer does not understand what you want to multiply.
For example, you can’t just write c=2b, it will be wrong!

The expression on the right side of the assignment epression allows you to calculate values using various formulas.

What expression can contain
• integer and real numbers (in real numbers, the integer and fractional parts are separated by a dot, not a comma, as is customary in mathematics)
• signs of arithmetic operators:
+ addition
- subtraction
* multiplication
/ division
% remainder of the division

• calls to standard functions through the Math class 
Math.abs(i) absolute value of i   \(|i|\)
Math.sqrt(x) \(\sqrt x\)
Math.pow(x,y) \(x^y\)
• parentheses to reorder

Any programming language includes many built-in functions that can be used in arithmetic expressions.
To use additional functions, you often have to connect additional libraries.

For example, the most commonly used standard mathematical functions and their writing in Java
Math.abs(i) absolute value of i  \(|i|\)
Math.sqrt(x) \(\sqrt x\)
Math.pow(x,y) \(x^y\)

Remember that the function argument is always written in brackets.

Rules for writing arithmetic expressions in a programming language

Suppose we need to calculate an expression written in mathematical form in this way:
Before writing a program that will calculate the result for us, we formulate the RULES for writing algebraic expressions in a programming language:
1. Expressions contain numbers, names of other variables, operators, parentheses, function names
2. Arithmetic operators (+, -, *, /,%)
3. The separator of the integer and fractional parts is the point.
4. The expression is written one per line (linear recording of expressions), the characters are sequentially arranged one after another, ALL operation signs are affixed; parentheses are used


Thus, following the rules for writing arithmetic expressions, we must translate this (mathematical notation) fraction into a line.
Because Since the numerator and denominator are complex (that is, they contain two or more operators), then when writing to a linear form, it is necessary to take the expressions in the numerator and denominator in brackets.
Thus, a linear record of such an expression will look like this:

(2*17.56*17.56)/(7*2.47*0.43)

We will write a program to calculate this expression:
for this we decide on the input and output data

input:  because we know all the values, then you don’t need to enter anything from the keyboard, therefore there will be no input data

output: the program should display the result of this arithmetic expression (you can put it into any variable, or you can immediately display the value on the screen).

We will immediately display the result of the expression without saving it in any variable.
Because if we have a fraction, then the result will be a real number
public class Main {
    public static void main(String[] args) {
        System.out.print((2*17.56*17.56)/(7*2.47*0.43));
    }
}

Run the program on the computer and make sure that it produces a result equal to 82,949843

After that, complete the task.

In Java programming language, there are two division operations:
/ division and % calculation of the remainder of the division.

What to remember:
1) The operation of calculating the remainder of division (%) is performed ONLY on integers
2) The result of the division operation (/) depends on the type of operands
The rule here is as follows:
When dividing an integer by an integer, the fractional part is always discarded, regardless of what type of variable we store the value!

When saving the material result into an integer variable, the fractional part will also be discarded

Let's analyze examples of performing division operations:
int i;
double x;
i = 7;
x = i / 4;            // x=1, divides the integer into the integer

x = i / 4.;           // x=1.75, divides the integer into the real (4 - without a dot is perceived as an integer, 4. (with a dot) - it's a real number!)

x =(double) i / 4;    // x=1.75, divides the real into the integer  - here the variable i is converted to a real number - this is an explicit conversion of type