Skip to main content

Chapte 9 What is Operator and Types Explain in Details

Post Intro:- So Frirnds Fainaly Hum log ab es post main Operator Kiya hota hai and Kitne Types ke hota hai, and kaise declared karna hai, and a propar example ke sath dekne bale hai.

Operator :

Operator is a specail symbol used for find logical and Mathematical Operation on data or variable in program.

Operand :- 

Operand is a data or variable on which the operation is to be perfromed.

Types of Operator:

  1. ⇒Arithmetic Operators
  2. ⇒Relational Operators
  3. ⇒Logical Operators
  4. ⇒Assignment Operators
  5. ⇒Bitwise Operators
  6. ⇒Increment/ Decrement Operators
  7. ⇒Conditional Operators 
Arithmetic Operators :  Used for mathematical operation.

Symbol

Operation

Examples

+

Addition

a + b

-

Subtraction

a- b

*

Multiplication

a*b

/

Division

a/b

%

Modulus

a % b


Example of Arithmetic Operator :


class Tech369kk
{
 public static void main(String[] args)
 {
 int a=10,b=3;
 System.out.println("Add="+(a+b));
 System.out.println("Sub="+(a-b));
 System.out.println("Multi="+(a*b));
 System.out.println("Div="+(a/b));
//  Note:-modulus(%) always holds remainder value  i mean ses
 System.out.println("Mod="+(a%b));
 }
}


Output : 


PS D:\Learning File\BCA\BCA 3rd Sem\JAVA OOP\BLOG> javac Blog.java
PS D:\Learning File\BCA\BCA 3rd Sem\JAVA OOP\BLOG> java Tech369kk
Add=13
Sub=7
Multi=30
Div=3
Mod=1     // Given Reminder




// Get user input find only addition value

import java.util.Scanner;
class Bloog{
  public static void main(String[] args) {
    Scanner obj = new Scanner(System.in);
    System.out.println("Enter a value : ");
    int a=obj.nextLine();
    System.out.println("Enter b value : ");
    int b=obj.nextLine();
    int c= a+b;
    System.out.println("Total Addition value is :" +c);
  }
}



Relational Operators:  Used for Comaparison  Operations 

  • Here:     0 means False
  •                1 means True

Symbol

Operation

Examples

==

Equal to

2==3 return 0

!=

Not equal to

2!=3 return 1

> 

Greater than

2>3 return 0

< 

Less than

2<3 return 1


>=

Greater than

or

equal to


2>=3 return 0


<=

Less than

or

equal to


2<=3 return 1



Example of RelatiOperator :


class Relational{
 public static void main(String[] args){
    int a=10,b=5;
   
    // if (a==b){     //False
    // if (a!=b){     //True
    // if (a>b){        //True  
    // if (a<b){       // False
    // if (a>=b){       // True
    if (a<=b){          // False
        System.out.println("Return 0 means True");
    }
    else{
        System.out.println("Return 1 Means False");
    }
}
}



Logical Operators:  Used for Conditional  Operations 

Symbol

Operation

Examples

&&

AND

if(a>b && x>z)

||

OR

if(x>y || x>z)

!

NOT

If(!(x>y))

 Note:- 

  • (a>b) && (a > c) Here this expression returns true if both conditions are true.
  • (a>b) || (b>c) Here this expression returns true if any one or both conditions are true.
  • !(a>b) Not operator reverses the state means if the condition is true it returns false and if the condition is false it returns true  .
Example of Logical Operators
  • A. And Operator (&&)


A. And Operator (&&)
class Logical{
public static void main(String[] args)
{
 int a=10,b=30,c=40;
if(a>b && a>c){
    System.out.println("a is greatest");
}
 if(b>a && b>c){
    System.out.println("b is greatest");
}
 if(c>a && c>b){
    System.out.println("c is greatest");
}
}
}


Output :

C is greatest


  • B. Or Operator (||)


B. Or Operator(||)
class Logical{
public static void main(String[] args)
{
 int a=10,b=30,c=40;
if(a>c || a>c){
    System.out.println("a is greatest");
}
 if(b>a || b>c){
    System.out.println("b is greatest");
}
 if(c>a || c>b){
    System.out.println("c is greatest");
}
}
}



Output :


PS D:\Learning File\BCA\BCA 3rd Sem\JAVA OOP\BLOG> java Logical  
b is greatest
c is greatest



Same as used C. Or Not Operator In Java


Assignment Operators :   

Symbol

Example

Same As

=

x=y

x=y

+=

x+=y

x=x + y

-=

x-=y

x=x-y

=

x=y

x=x*y

/=

x/=y

x=x/y

%=

x%=y

x=x%y

Example of Assignment Operator


class Assignment
{
 public static void main(String[] args)
 {
    int a=10,b=4, c;
    // a+=b;  or
    c=a+b;
    System.out.println("Addition of a and b:"+c);

    int x2=5,y2=3;
    x2-=y2;//x2=x2-y2
    System.out.println(x2);

    int x3=5,y3=3;
    x3*=y3;//x3=x3*y3
    System.out.println(x3);

    int x4=5,y4=3;
    x4/=y4;//x4=x4/y4
    System.out.println(x4);

    int x5=5,y5=3;
    x5%=y5;//x5=x5%y5
    System.out.println(x5);
 }
}



Output:-


Addition of a and b:14
2
15
1
2



Bitwise Operators :   

Symbol

Operation

Example

&

AND

x&y

|

OR

x|y

<< 

Shift Left

X<<2

>> 

Shift Right

x>>2

^

X-OR

x^y


Example of Bitwise Operator 


class Bitwise
{
 public static void main(String[] args)
 {
     //variable declaration
    int a=10,b=3,c;
    c=a&b;      //AND Operation
    System.out.println("a&b="+c);
    c=a|b;      //OR Operation
    System.out.println("a|b="+c);
    c=a>>2;     //Shift right Operation
    System.out.println("a>>2="+c);
    c=a<<2;     //Shift left Operation
    System.out.println("a<<2="+c);
    c=a^2;      //X-OR Operation
    System.out.println("a^2="+c);
 }
}


Output 


PS D:\Learning File\BCA\BCA 3rd Sem\JAVA OOP\BLOg> java Bitwise
a&b=2
a|b=11
a>>2=2
a<<2=40
a^2=8



Increment/Decrement Operators :   

Symbol

Name

Function

Example

++

Increment

It increments the value by 1

++x

--

Decrement

It decrement the value by 1

--x


Example of Increment And Decrement:- 


class IncDec
{
 public static void main(String[] args)
 {//variable declaration
  int a=5,b=10;
   System.out.println(++a);
   System.out.println(--b);
 }
}


Output :

PS D:\Learning File\BCA\BCA 3rd Sem\JAVA OOP\BLOg> java IncDec  
6
9



Conditional  Operators :- If the condition is true second part will execute otherwise third part will execute.

Example of Condiitonal Operators:


Q. Check Greater Number
class Ternarry{
  public static void main(String[] args){
    int a=5,b=10,max; // Variable declaration
     //same as min
    max=a>b?a:b;
    System.out.println("Greater value is "+ max);  
    //don't be confused,here + is separator in java
  }
}



Output :- 

PS D:\Learning File\BCA\BCA 3rd Sem\JAVA OOP\BLOg> java Ternarry
Greater value is 10

I hope this is helpful for you thanks.

Comments

Popular posts from this blog

Assignment of ITA/ Information Technology and Application BCA- Technology369kk

Q1. What is  computer Explain basic computer architecture and Difference components.  2. Discuss the use of memory in computer system, Explain memory hierarchy  in details. 3. What is software? Explain difference types of software with explain. 4. Write short notes on the given:- (I) Internet. (II) LAN (Local area network ) (III) Search engine (IV) Web browser  Q 1.What is computer Explain basic computer architecture, Difference components of computer.   Computer :- Computer is defined as an electronic device that takes input data and instructions from the user and after processing them, it generates useful and desired output quickly.   A computer is designed to execute applications and provides a variety of solutions through integrated hardware and software components.                            It is fast and automatic device. It works with the help of programs and represents the d...

C++ and Java Practical All Questions Answers - BCA -Technology369kk

C++ and Java  In this post see most important questions for practical questions given by college all questions with answers . Guys I want to say that this is only for suggested post for your practical please request to you change same alphabets, words or anything  methods name and variables name because if you write all words same then this is copy paste for another peoples.  Used Topics:  Keywords, Variables, Condition Statements, Function , Array, Structure, Pointer.                           In OOPs, Class and Objects, Constructor, Poly morph, Encapsulation, Access Specifiers,                               Inheritance etc.  So, Without Time Lose Come to the Points, let's go start Now:        *************************************************************************  C++ 12 ...

Assignment of PMO (Principal of Management and Organization) - Technology369kk

 ** Assignment Of PMO ** Agenda: -  4 Questions discuss in this post. Question 1. Write a d etails note on selection why it Called. negative process.  Question 2. Write a details note on 'span of control. Question 3. Planning is an essential process, do you agree ? Discuss  Question 4. Write a note on management function. Q 1. Write a d etails note on selection why it called negative process.  Ans :-  Selection is the process of choosing the most suitable candidates out of the several candidates available.          Selection is a negative process because there may be more rejected then those selected in most of the candidates that is called selection is a negative process. → Selection process has the following steps:-  [ A .] Screening of applicants - Based on the screening of applicants only those candidates. It Called further process of selection. Who are found eligible for the job Standards of the the organization. [ B .] S...