Heim > Java > javaLernprogramm > Hauptteil

Java-Operatoren

王林
Freigeben: 2024-08-30 15:18:56
Original
189 Leute haben es durchsucht

Der folgende Artikel enthält eine Übersicht über Java-Operatoren. Der Java-Operator bezeichnet ein Symbol, das bei der Ausführung mehrerer Operationen an einem oder mehreren Operanden hilft. Operatoren können je nach Anforderung +, -, /, * usw. sein.

Starten Sie Ihren kostenlosen Softwareentwicklungskurs

Webentwicklung, Programmiersprachen, Softwaretests und andere

Es gibt verschiedene Arten von Operatoren.

  • Arithmetische Operatoren
  • Bitweise Operatoren
  • Zuweisungsoperatoren
  • Ternärer Operator
  • Auto-Inkrement- und Auto-Dekrement-Operatoren
  • Vergleichsoperatoren oder relationale Operatoren
  • Logische Operatoren
  • Schichtoperatoren

Operatortypen in Java

Im Folgenden sind die Arten von Operatoren in Java aufgeführt:

1. Arithmetische Operatoren

Arithmetische Operatoren werden verwendet, um mehrere arithmetische Operationen auszuführen.

Im Folgenden sind die arithmetischen Operatoren in Java aufgeführt.

Operator Name/ Symbol Definition Example
Addition(+) It helps in adding two values. A+B
Subtraction(-) It helps in subtracting two values. A-B
Modulus(%) It helps in getting the remainder obtained by dividing two values. A%B
Multiplication( * ) It helps in multiplying two values. A*B
Division ( / ) Helps in dividing two values. A/B

2. Bitweise Operatoren

Bitweise Operatoren werden häufig zur Durchführung von Bitverschiebungen und bitweisen Operationen in Java verwendet.

Im Folgenden sind die häufig verwendeten bitweisen Operatoren aufgeführt.

Operator Name/ Symbol Definition Example
Bitwise AND operator (&) It helps in comparing 2 operand’s corresponding bits. 1 will be returned if both the bits are 1; else 0 will be returned. A&B
Bitwise OR operator (|) It helps in comparing 2 operand’s corresponding bits. 1 will be returned if one of the bit is 1; else 0 will be returned. A|B
Bitwise XOR operator (^) It helps in comparing 2 operand’s corresponding bits. 1 will be returned if the corresponding bits are dissimilar, else 0 will be returned. A^B
Bitwise complement operator (~) It helps in inverting the pattern of bits. That is, 1 will be changed to 0 and 0 will be changed to 1. ~B

3. Zuweisungsoperatoren

Zuweisungsoperatoren werden zum Zuweisen von Werten zu bestimmten Variablen verwendet.

Im Folgenden sind die Zuweisungsoperatoren in Java aufgeführt.

Operator Name/ Symbol Definition Example
-= It helps subtract the right and left operators, thereby assigning the obtained result to the operator on the left. A-=B
/= Helps in dividing the right and left operators and thereby assigning the obtained result to the operator in the left. A/=B
*= It helps multiply right and left operators and thereby assign the obtained result to the operator on the left. A*=B
+= It helps add right and left operators and thereby assign the obtained result to the operator on the left. A+=B
^= Left operand value will be raised to the right operator power. A^=B
%= A modulus operator will be applied. A%=B

4. Ternäre Operatoren

In Java wird der ternäre Operator hauptsächlich zum Ersetzen von Wenn-Dann-Sonst-Bedingungen verwendet. Es handelt sich um eine einzeilige Anweisung, die in der Java-Programmierung weit verbreitet ist und nur drei Operanden benötigt.

Operator Name/ Symbol Definition Example
condition?v1: v2 V1 will be returned if the condition mentioned is true, and v2 will be returned if the condition is false. A>B?A:B

5. Auto-Inkrement-Operatoren und Auto-Dekrement-Operatoren

Auto-Inkrement- und Auto-Dekrement-Operatoren in Java helfen beim Erhöhen bzw. Verringern der Werte um 1.

Operator Name/ Symbol Definition Example
++ The value will be incremented by 1. A++; It is similar to A+=1
The value will be decremented by 1. A–; It is similar to A-=1

6. Vergleichsoperatoren oder relationale Operatoren

Relationale Operatoren sind Operatoren, die bei der Überprüfung der Operandengleichheit helfen. Darüber hinaus werden diese Operatoren auch zum Vergleichen von zwei oder mehr Werten verwendet.

Operator Name/ Symbol Definition Example
equals to(==) If the left operand is equal to the right operand, true will be returned; else, false. A==B
not equal to(!=) If the left operand is not equal to the right operand, true will be returned; else, false. A!=B
less than(<)  If the left operand is less than the right operand, true will be returned; else, false. A
greater than(>) If the left operand is greater than the right operand, true will be returned; else, false. A>B
greater than or equal to(>=) If the left operand is greater than or equal to the right operand, true will be returned else, false. A>=B
Less than or equal to(<=) If the left operand is less than or equal to the right operand, true will be returned else, false. A<=B

7. Logische Operatoren

Logische Operatoren in Java werden häufig in booleschen Ausdrücken verwendet.

Unten sind die logischen Operatoren in Java.

Operator Name/ Symbol Definition Example
Conditional AND(&&) If both the Boolean expressions are satisfied, true will be returned else, false. AD
Conditional OR(||) If any of the Boolean expression is satisfied, true will be returned; else, false. AD
Logical NOT(!) It helps in inverting the operand’s logical state. That is, 1 will be changed to 0 and 0 will be changed to 1. !B

8. Schichtoperatoren

Verschiebungsoperatoren in Java werden verwendet, um die Bits je nach Anforderung nach links oder rechts zu verschieben.

Im Folgenden sind die Shift-Operatoren aufgeführt.

Operator Name/ Symbol Definition Example
Left Shift Operator ( << ) X in binary notation will be shifted y bits left by shifting the zeroes from the right. A<<2
Right Shift Operator ( >> ) X in binary notation will be shifted y bits right by discarding shifted bits. B>>2
Unsigned Right Shift Operator ( >>> ) X in binary notation will be shifted y bits right by discarding shifted bits and shifting the zeroes from the right. A>>>2

Lassen Sie uns sehen, wie die Priorität dieser Operatoren sein wird.

Operator Precedence
Postfix Operators Exp++ Exp–
Unary Operators ++Exp –Exp +_Exp –Exp~ !
Multiplicative Operators * / %
Additive Operators + –
Shift Operators << >> >>>
Relational Operators < > <= >= instanceof
Equality Operators == !=
Bitwise AND Operator &
Bitwise exclusive OR Operator ^
Bitwise inclusive OR Operator |
Logical AND Operator &&
Logical OR Operator ||
Ternary Operators ?:
Assignment Operators = += -= *= /= %= &= ^= |= <<= >>= >>>=

Das obige ist der detaillierte Inhalt vonJava-Operatoren. Für weitere Informationen folgen Sie bitte anderen verwandten Artikeln auf der PHP chinesischen Website!

Verwandte Etiketten:
Quelle:php
Erklärung dieser Website
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn
Beliebte Tutorials
Mehr>
Neueste Downloads
Mehr>
Web-Effekte
Quellcode der Website
Website-Materialien
Frontend-Vorlage
Über uns Haftungsausschluss Sitemap
Chinesische PHP-Website:Online-PHP-Schulung für das Gemeinwohl,Helfen Sie PHP-Lernenden, sich schnell weiterzuentwickeln!