Javaにおける関係演算子 - Scalerトピックス
原題: Relational Operators in Java - Scaler Topics
分析結果
- カテゴリ
- AI
- 重要度
- 54
- トレンドスコア
- 18
- 要約
- Javaの関係演算子は、2つの値を比較し、その関係を評価するために使用されます。主な関係演算子には、等しい(==)、等しくない(!=)、より大きい(>)、より小さい(<)、より大きいか等しい(>=)、より小さいか等しい(<=)があります。これらの演算子は、条件文やループでの制御フローにおいて重要な役割を果たします。正しい使用法を理解することで、プログラムの論理を構築する際に役立ちます。
- キーワード
Relational Operators in Java - Scaler Topics Experience Academy Data Science AI/ML DevOps Neovarsity Topics Explore New Skill Test Courses Free Masterclass Search for Articles, Topics Experience Experience Scaler Relational Operators in Java Relational Operators in Java Java Cheatsheet Relational Operators in Java By Ganesh Kumar Marimuthu 2 mins read Last updated: 14 Apr 2024 307 views Video Tutorial FREE This video belongs to Java Course - Mastering the Fundamentals 12 modules Certificate Go to Course Go to Course Topics Covered Relational operators in Java are binary Java operators used to check the relations between two operands. They return a boolean value ( true or false ) by comparing the two operands. Java supports a variety of relational operators, including greater than ( > ), less than ( < ), greater than or equal to ( >= ), less than or equal to ( <= ), equal to ( == ), and not equal to ( != ). These operators are commonly used in conditional statements, loops, and other programming constructs to make decisions based on the values of variables or expressions. What are Relational Operators in Java? In programming, we often need to check the relation between two operands such as equality, in-equality, etc. Relational operators in Java are used to check the relations between two operands. After comparison, the relational operators return a boolean value. Relational operators are mainly used for conditional checks in if , else , for , while , etc. Syntax The syntax for relational operators in Java is given below: operand1 - The first variable to be compared operand2 - The second variable to be compared relational_operator - The relational operator to check relation between operand1 and operand2 . Types of Relational Operators in Java There are six types of relational operators in Java, and they can be found below: Equal To ( == ) - Checks if two operands are equal Not Equal To ( != ) - Checks if two operands are not equal Greater Than ( > ) - Checks if one operand is greater than the other Less Than ( < ) - Checks if one operand is less than the other Greater Than or Equal To ( >= ) - Checks if one operand is either greater than or equal to the other. Less Than or Equal To ( <= ) - Checks if one operand is either less than or equal to the other. Equal To ( == ) The Equal To ( == ) operator checks if two operands are equal. It returns true if two operands are equal; else false . The syntax of the == operator is: Not Equal To ( != ) The Not Equal To ( != ) operator checks if two operands are not equal. It returns true if two operands are not equal; else false . The syntax of the != operator is: Greater Than ( > ) The Greater Than ( > ) operator checks if one operand is greater than the other. It returns true if the first operand is greater than the other; else false . The syntax for the > operator is: Less Than ( < ) The Less Than ( < ) operator checks if one operand is less than the other. It returns true if the first operand is less than the other; else false . The syntax for the < operator is: Greater Than or Equal To ( >= ) The Greater Than or Equal To ( >= ) operator checks whether one operand is greater than or equal to the other. It returns true if the first operand is greater than or equal to the other; else false . The syntax for the >= operator is: Less Than or Equal To ( <= ) The Less Than or Equal To ( <= ) operator checks if one operand is either less than or equal to the other. It returns true if the first operand is less than or equal the other; else false . The syntax for the <= operator is: Examples of Relational Operators in Java Equal To ( == ) We used the == operator to check if two values are equal. Output Not Equal To ( != ) We used the != operator to check if the two values were not equal equal. Output: Greater Than ( > ) We used the > operator to check if one value is greater than the other. Output: Less Than ( < ) We used the < operator to check if one value is less than the other. Output: Greater Than or Equal To ( >= ) We used the >= operator to check whether one value is greater than or equal to the other. Output: Less Than or Equal To ( <= ) We used the <= operator to check if one value is either less than or equal to the other. Output: Conclusion Relational operators in Java are binary operators used to check the relations between two operands Relational operators return a boolean value There are six relational operators in Java: == , != , < , > , <= , and >= Relational operators are mainly used for conditional checks if, else, for, while, etc.