Let's try to write a calculator for primes
Our task is to display some arithmetic expression on the screen and make the computer count it.
For example, this:
5 + 7 = 12
Moreover, instead of 5 and 7, there may be different numbers, depending on the values of the variables a and b in the program.
In the output operator, you can output not just text, but also the values of variables, as well as the result of an arithmetic expression. Moreover, the output sequence may be different.
For example, you can output the above expression by writing:
System.out.print(a+"+"+b+"="+(a+b));
If you want to output the value of a variable, then you just need to specify its name without quotes. If we want to output the result of an arithmetic expression, then it is enough to simply write the arithmetic expression correctly.
*** Advanced material***
The number of output specifiers in the format string is not limited, the main thing for each qualifier is to list all the values that will be substituted for the template after the format string, by comma.
For example:
System.out.printf("%d+%d=%d",a,b,a+b);
The format string indicates three specifiers for displaying integer values instead. The substitution order is direct: instead of the first template
%d
, the value of the variable
a
is displayed; instead of the second, the value of the variable
b
; and instead of the third, the value of the expression
a + b
Now let's write a program that outputs the result of basic arithmetic operations with these variables