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!

Task
In the 7th line write the assignment expression, as a result of which the variable c takes the value of the sum of the variables a and b
Java
1
import java.util.Scanner;  
2
public class Main {  
3
    public static void main(String[] args) {  
4
        Scanner in = new Scanner(System.in);  
5
        int a,b,c;  
6
        a = in.nextInt();  
7
        b = in.nextInt();  
8
9
        System.out.print(c) ;  
10
    }  
11
}  
Your last submission is saved in the editor window.
     

Results:

All results: