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.