[Java] First learning java #3 expressions and operators

less than 1 minute read

What is an expression?

public class Main {
public static void main(String[] args) {
int a;
int b;
a = 20;
b =a+5;
System.out.println(a);
System.out.println(b);
}
}

Execution result

20
twenty five

A thing like the sixth line is called an expression. “A”, “b”, and “5” are called operands, and “+” and “*” are called operators. As with any complex formula, all formulas consist of these two.

literal

What is described in the source code such as “5” or “hello, world” among operants is called a literal. Literals have data types such as (int).

Escape sequence

A special character is expressed by the notation method that is described by the yen symbol and the character following it.

Notation Meaning
\” Double quotation mark symbol
¥ ′ Quotation mark symbol
\ Yen sign
\N Line feed

operator

Operator Function
+ Addition
Subtraction
* Multiplication
/ Division
% Remainder of division (surplus)
+ Concatenation of strings
= Substitute right side for left side
+= Adds the left side and the right side and assigns to the left side (there is an arithmetic operator)
++ Increase value by one
- —– Decrement the value by one

Tags:

Updated: