slide 1
Operators and Expressions in Java Language
slide 2
operator
According to the function of the operator, there are 7 types of operators:
1. Arithmetic operators,
2. Relational operators,
3. Logical operators,
4. Bitwise operators,
5. Assignment operator,
6. Conditional operators,
7. Other operators
slide 3
operator
According to the number of connection operands, there are
- unary (mesh) operator,
- binary (mesh) operator,
- Ternary (mesh) operator.
slide 4
arithmetic operator
one. Binary operators +, -, *, /, %
two. Unary operators ++, --,+, -
slide 5
Logical Operators
Logical AND (&&), Logical OR (||), and Logical NOT (!).
slide 6
assignment operator (binary)
one. The assignment operator "=" is used to assign the data or expression on the right side of the operator "=" to the variable on the left.
Generalized assignment operators: +=, -=, *=, /=, %=, &=, |=
2. When the types on both sides of the assignment operator are inconsistent:
- automatic type conversion
- cast
slide 7
Ternary conditional operator
one. The structure of the ternary conditional expression is:
(condition) ?result1:result2;
two. The calculation process of the conditional expression is as follows: first calculate the logical expression or relational expression as the condition, the value of the expression is result 1 when the return value is true, and the value of the expression is result 2 when the return value is false.
slide 8
Prompt: I want you to act as the java console. I will type the command and you will reply with what the java console should display. I want you to only echo terminal output within a unique block of code, and nothing else. Don't write explanations. Unless I instruct you to do so.
• Use GPT to emulate IDE to run FindMinMax .java
package com.dal.basic;
public class FindMinMax{
public static void main(String []args)
{
double temp, max, min;
double d1=1,d2=-9.9,d3=96.9;
temp=d1>d2?d1:d2;
temp=temp>d3?temp:d3;
max=temp;
temp=d1<d2?d1:d2;
temp=temp<d3?temp:d3;
min=temp;
System.out.println("max="+max);
System.out.println("min="+min);
}
}
Sample code download link https://pan.baidu.com/s/1_jVUj3H8aeUHiDdpg0Liaw?pwd=3xbw
slide 9
other operators
- (), [], cast operators;
- Object operator instanceof: To judge whether a specific object
is an instantiated object of a certain class (or other subclasses), if so, return true, otherwise return false; (detailed description of the course later. - Memory allocation operator new: Allocate memory space for arrays and class objects. (Detailed description of the course later)