In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to use the Java relational operator". Interested friends may wish to take a look at it. The method introduced in this paper is simple, fast and practical. Let the editor take you to learn how to use the Java relational operator.
1. Operator 1: equals operator (= =)
two。 Operator 2: the "not equal" operator (! =)
3. Operator 3: greater than operator (>)
Operator: forms the basic building block of any programming language. Java also provides many types of operators that you can use to perform various calculations and functions, including logic, arithmetic, relationships, and so on, as needed. They are classified according to the functions they provide.
Operator type:
Arithmetic operator
Unary operator
Assignment operator
Relational operator
Logical operator
Ternary operator
Bitwise operator
Shift operator
Relational operator: a set of binary operators used to check the relationship between two operands, including equality, greater than, less than, and so on. They return a Boolean result after comparison and are widely used in loop statements, conditional if- else statements, and so on. The general format for representing relational operators is:
Syntax:
Variable 1 relation _ operator variable 2
Let's look at each relational operator in Java:
1. Operator 1: equals operator (= =)
This operator is used to check whether two given operands are equal. If the Operand on the left is equal to the Operand on the right, the operator returns true, otherwise it returns false.
Syntax:
Variable 1 = = variable 2
Examples:
Var1 = "haiyong" var2 = 20 var1 = = var2 result is false
Example:
Import java.io.*;class GFG {/ / main driver public static void main (String [] args) {/ / initialization variables int var1 = 5, var2 = 10, var3 = 5; / / display var1, var2, var3 System.out.println ("Var1 =" + var1); System.out.println ("Var2 =" + var2); System.out.println ("Var3 =" + var3) / / compare var1 and var2 and print the corresponding Boolean System.out.println ("var1 = = var2:" + (var1 = = var2)); / / compare var1 and var3 and print the corresponding Boolean System.out.println ("var1 = = var3:" (var1 = = var3));}}
Output:
Var1 = 5 Var2 = 10 Var3 = 5 var1 = = var2: false var1 = = var3: true2. Operator 2: the "not equal" operator (! =)
This operator is used to check whether two given operands are equal. Its function is the opposite of that of the equal operator. Returns true if the Operand on the left is not equal to the Operand on the right, otherwise returns false.
Syntax:
Variable 1! = variable 2
Examples:
Var1 = "haiyong" var2 = 20 var1! = var2 result is true
Example:
Import java.io.*;class GFG {/ / main driver method public static void main (String [] args) {/ / initialization variables int var1 = 5, var2 = 10, var3 = 5; / / display var1, var2, var3 System.out.println ("Var1 =" + var1); System.out.println ("Var2 =" + var2); System.out.println ("Var3 =" + var3) / compare var1 and var2 and print the corresponding Boolean System.out.println ("var1 = = var2:" + (var1! = var2)); / / compare var1 and var3 and print the corresponding Boolean System.out.println ("var1 = = var3:" + (var1! = var3));}} * * output * * ``javaVar1 = 5 Var2 = 10 Var3 = 5 var1 = var2: true var1 = var3: false3. Operator 3: greater than operator (>)
This checks whether the first Operand is greater than the second Operand. The operator returns true when the Operand on the left is greater than the Operand on the right.
Syntax:
Variable 1 > variable 2
Examples:
Var1 = 30 var2 = 20 var1 > var2 result is true
Example:
Import java.io.*;class GFG {/ / main driver method public static void main (String [] args) {/ / initialization variables int var1 = 30, var2 = 20, var3 = 5; / / display var1, var2, var3 System.out.println ("Var1 =" + var1); System.out.println ("Var2 =" + var2); System.out.println ("Var3 =" + var3) / compare var1 and var2 and print the corresponding Boolean System.out.println ("var1 > var2:" + (var1 > var2)); / / compare var1 and var3 and print the corresponding Boolean System.out.println ("var3 > var1:" + (var3 > = var1)) } * * output * * ```javaVar1 = 30Var2 = 20Var3 = 5var1 > var2: truevar3 > var1: false at this point, I believe you have a better understanding of "how to use the Java relational operator". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.