[go: up one dir, main page]

0% found this document useful (0 votes)
11 views5 pages

Operators

Uploaded by

SRIHARI RAMESH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
11 views5 pages

Operators

Uploaded by

SRIHARI RAMESH
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 5
19/23, 10007 PM Java Tutoviak: Operators, Types of Operators & Expressions in Java | CodsWithHarry CodeWithHarry Menu & t Java Tutorial: Operators, Types of Operators & Exor... Show Course Contents © Overview Q&A Downloads Announcements < Java Tutorial: Operators, Types of Operators & Expressions in Java * An operator is a symbol that the compiler to perform a specific operation on operands. * Example: atb=c * In the above example, 'a’ and 'b' are operands on which the’ operator is applied. Types of operators : 1. Arithmetic Operators : Arithmetic operators are used to perform mathematical operations such as addition, division, etc on expressions. Arithmetic operators cannot work with Booleans. % operator can work on floats and doubles. Let x=7 and y=2 ae Exampl Operator Description hitps:lwwn-codewithharry.comvideos/java-utorialsfor-beginners-8) 19/23, 10007 PM Java Tutoviak: Operators, Types of Operators & Expressions in Java | CodsWithHarry x+y= + (Addition) Used to add two numbers 9 y : Used to subtract the right-hand side value from the 5 x-y= (Subtraction) left-hand side value y x*ys (Multiplicatio Used to multiply two values. 4 n) x/y= / (Division) Used to divide left-hand Value by right-hand value. 3 Used to print the remainder after dividing the left-hand x%y= % (Modulus) side value from 1 the right-hand side value. 4 Increases the value of operand by 1. xt = 8 (Increment) Decreases the value of operand by 1. (Decrement) 2. Comparison Operators : * As the name suggests, these operators are used to compare two operands. * Let x=7 and y=2 Operator Description Example Checks if two operands (Equal are equal. Returns a y--> False to) boolean value. Checks if two operands != (Not are not equal. Returns x != y --> True equal a boolean value. Checks if the left-hand > side value is greater (Greater than the right-hand =x > y--> True than) side value. Returns a boolean value. <(Less Checks if the left-hand x < y--> False than) __ side value is smaller than the right-hand hitps:lwwn-codewithharry.comvideos/java-utorialsfor-beginners-8) 215 ‘80023, 1007 PM Java Tula: Operator, Types of Operators & Expressions in Java| CodelithHarry side value. Returns a boolean value. Checks if the left-hand >= side value is greater (Greater than or equal to the x >=y--> True than or right-hand side value. equal to) Returns a boolean value. Checks if the left-hand side value is less than <= (Less : or equal to the right- than or . x <= y-->False hand side value. equal to) Returns a boolean value. 3. Logical Operators : * These operators determine the logic in an expression containing two or more values or variables. © Letx=8andy=2 Bk | xy && Returns true if both operands (logical xley—-> are true. and) True Il x operand is true. on) True Returns true if the result of the (x not) versa False 4. Bitwise Operators : * These operators perform the operations on every bit of a number. * Let x =2 and y=3. So 2 in binary is 100, and 3 is ON. Operat age or Description Example & 181 =1, 0&1=0,1&0=0,1&1=1, 0&0 =0 (A & B) = (100 & O11) = 000 (bitwis hitps:lwwn-codewithharry.comvideos/java-utorialsfor-beginners-8) 35 19/23, 10007 PM Java Tutoviak: Operators, Types of Operators & Expressions in Java | CodsWithHarry e and) | (bitwis 1&0 =1, 0&1=1,1&1=1, O&0=0 (Al B) = (100 | on) = 111 eor) (bitwis 1&0 =1, 0&1=1,1&1=0, 0&0=0 (A*B) = (1004011) = 11 e XOR) << (left This operator moves the value left by . 13<<2 = 52(decimal) shift) the number of bits specified. > (right shift) This operator moves the value left by . 13>>2 = 3(decimal) the number of bits specified. Precedence of operators The operators are applied and evaluated based on precedence. For example, (+,-) has less precedence compared to (*, /). Hence * and / are evaluated first. In case we like to change this order, we use parenthesis (). Code as Described in the Video package public class CWH_Ch2_Operators public static void main(String // 1, Arithmetic Operators int 4 // int b = 6 % a; // Modulo Operator // 4,8%1,1 --> Returns Decimal Remainder // 2, Assignment Operators int 9 3 system println // 3. Comparison Operators // System,out.print1n(64<6) ; // 4, Logical Operators hitps:lwwn-codewithharry.comvideos/java-utorialsfor-beginners-8) 45 923, 1007 Java Tura Operators, Types of Operators & Expressions in ava | CodeWihiany // System.out.print1n(64>5 && 64>98); System.out.print1n(64>5 || 64>98); // 5. Bitwise Operators System, out.print1n(2&3) ; MW 10 M7 11 W oo / 10 Handwritten Notes: Click To Download Ultimate Java Cheatsheet: Click To Download Previous Next A 8 CodeWithHarry Copyright © 2022 CodeWithHarry.com #¥O090 hips slw.codewithharry.comivideos/java-tutorialsfor-beginners-8! 55

You might also like