0% found this document useful (0 votes)
35 views3 pages

Alloperator

The document is a Java program that demonstrates various unary, arithmetic, and bitwise operations through labeled blocks. It includes examples of incrementing and decrementing variables, performing arithmetic calculations, and using shift operators. Additionally, it illustrates the differences between logical and bitwise operators, as well as the ternary operator.

Uploaded by

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

Alloperator

The document is a Java program that demonstrates various unary, arithmetic, and bitwise operations through labeled blocks. It includes examples of incrementing and decrementing variables, performing arithmetic calculations, and using shift operators. Additionally, it illustrates the differences between logical and bitwise operators, as well as the ternary operator.

Uploaded by

AKSHAY PATIL
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

public class Main

{
public static void main(String[] args) {

unary1:{ int a = 10;


System.out.println("first block unary");
System.out.println(a++);
System.out.println(++a);
System.out.println(a--);
System.out.println(--a);
System.out.println(--a);

Unary2:{
int a = 10;
System.out.println(" \n second block unary");
System.out.println(a++ + ++a - --a + ++a);
System.out.println((a++)+(++a));

unary3:{

int a=-15;
System.out.println(" \n Third block unary");
System.out.println(~a);
System.out.println(~(~a));

}
unary4:{
System.out.println(" \n fourth block unary");
boolean b = false ;
System.out.println(!b);
System.out.println(!(!b));
}

Arithmetic:{

int a=10;
int b=5;
System.out.println(" \n Arithmetic operator");
System.out.println(a+b);//15
System.out.println(a-b);//5
System.out.println(a*b);//50
System.out.println(a/b);//2
System.out.println(a%b);//0
}

leftshift:{
int a = 4;
System.out.println(" \n Left Shift operator");
System.out.println(a<<2); //a * 2^2 == 16
System.out.println(a<<3); //a * 2^3 == 32
}
Rightshift:{
int a = 10;
System.out.println(" \n Right Shift operator");
System.out.println(a>>2); // a / 2^2 = 2
System.out.println(a>>3); // a / 2^3 = 1

javashift:{

System.out.println(" \n >>> operator");


//For positive number, >> and >>> works same
System.out.println(20>>2);
System.out.println(20>>>2) ;

//For negative number, >>> changes parity bit (MSB) to 0


System.out.println(-20>>2);
System.out.println(-20>>>2);
}

Logical_Or_Vs_bitwise_Or:{

/* The logical || operator doesn't check the second condition if the first
condition is true.
It checks the second condition only if the first one is false */

//The bitwise | operator always checks both conditions whether first


condition is true or false.

int a=10;
int b=5;
int c=20;
System.out.println("Logical OR vs Bitwise OR ");

System.out.println(a>b||a<c); //true
System.out.println(a>b|a<c); //true

System.out.println(a>b||a++<c);
System.out.println(a); // true //10
System.out.println(a>b|a++<c);
System.out.println(a); // true //11

Ternary_operator:{

System.out.println(" Ternary operator ");

int a = (10<5)?7:(5<2)?8:3;

System.out.println(a);
}

}
}

You might also like