Java All : Operators (Arithmetic-Assignment-Unary-Relational-Logical)
Concept Learning Code Sheets

Sum of Inputs #557

This is a program to learn different ways of getting the desired console output

Arithmetic Operators #3657

Addition, subtraction, multiplication, division and modulus operator

Simple Assignment and Compound Assignments #3661

Using simple assignment means = operator and special variations with arithmetic operators like +=, -=, *=, /= and %= .

Unary Operator Post and Pre Operations #3663

Understanding unary increment with post operation and pre operation example.

Relational operators usage for data comparison #3676

Use of equality check operator == and other relational operators like not equal to !=, less than < , greater than > , less than or equal to <= and greater than or equal to >=  operators.

Unary Operator plus, minus and inversion #3692

Understanding unary operator plus, minus and inversion.

Conditional or Logical Operators AND, OR #3698

Understanding the use of condition operators and (&&) and or (||)

Conditional Ternary Operators #3702

Understanding the use of conditional ternary operator with three operands

Operator precedence in arithmetic and unary expressions #3735

Understanding operator precedence with simple arithmetic and unary operators.

Operator precedence with brackets #3738

Understanding operator precedence when brackets are used.

Operator precedence with comparison and logical operators #3740

Understanding operator precedence with comparison(relational) and logical(conditional) operators.

Auto conversion, Widening Type Promotion or Implicit Casting #3787

Understanding rules of widening type promotions from byte->short->int->long->float->double.

Exam Paper Problems

Precedence of Operator #3911

( As In Exam - ICSE2014 )

Operators with higher precedence are evaluated before operators with relative

Operators with higher precedence are evaluated before operators with relatively lower precedence. Arrange the operators given below in order of higher precedence to lower precedence.

(i) &&
(ii) %
(iii) >=
(iv) ++

Ternary Operator Evaluation Problem #3959

( As In Exam - ICSE2015 )

Evaluate the value of n if the value of p=5, q=19
int n = (q-p) > (p

Evaluate the value of n if the value of p=5, q=19
int n = (q-p) > (p-q) ? (q-p) : (p-q);

if-else to ternary conversion #4069

( As In Exam - ICSE2018 )

Rewrite the following using ternary operator:
if (bill>10000)

Rewrite the following using ternary operator:
if (bill>10000)
discount=bill*10.0/100;
else
discount = bill*5.0/100;

operator identification #4100

( As In Exam - ICSE2017 )

Name the operators listed below
(i) <     ( ii) ++      (iii) &

Name the operators listed below
(i) <     ( ii) ++      (iii) &&     (iv) ?:

division versus modulus operator #4104

( As In Exam - ICSE2017 )

Write one difference between / and % operator.

Write one difference between / and % operator.

difference between == and equals() #4220

( As In Exam - ICSE2016 )

State the difference between == operator and equals() method.

State the difference between == operator and equals() method.

if-else to ternary operator #4244

( As In Exam - ICSE2016 )

Rewrite the following using ternary operator :
if(x%2 == 0)
Syste

Rewrite the following using ternary operator :
if(x%2 == 0)
System.out.print(“EVEN”);
else
System.out.print(“ODD”);

Expression evaluation incr – decr #7233

( As In Exam - ICSE2017 )

What is the value of x1 if x=5?
x1= ++x – x++ + –x

What is the value of x1 if x=5?
x1= ++x – x++ + –x

Solved Problems

Increment, Decrement operator Output Writing #3666

Write output of the following program instructions.

int a=10;
Sy

Write output of the following program instructions.

int a=10;
System.out.println(a++);
int b = –a;
System.out.println(b);
b= b++ – -a;
System.out.println(b++);
a= –b + ++a;
System.out.println(a);

Arithmetic operator with different data types Output Writing #3669

Write output of the following program instructions.

int a=5;
flo

Write output of the following program instructions.

int a=5;
float b=9.0f;
double c= a+b;
double d=b+a/2;
System.out.println(c);
System.out.println(d);

Assignment operators based Output Writing #3672

Write output of the following program instructions.

int a=10;
in

Write output of the following program instructions.

int a=10;
int b=a=12;
System.out.println(a+b);
b%=5;
a/=b;
System.out.println(a+b);

Relational operators based Output Writing #3682

Write output of the following program.

```class SP_RelationalOP
{
p

```

Write output of the following program.

```class SP_RelationalOP
{
public static void main(String[] args)
{
float x=2.35f;
int y=2;
System.out.println(x!=y);
System.out.println(x<y);
System.out.println(y>x);
System.out.println(y>=x);
System.out.println(y<=x);
System.out.println(x==2.35);
System.out.println(x==2.35f);
}
}```

Conditional Operator Output Value Proving #3704

Prove that output of the following program would be true.

<

Prove that output of the following program would be true.

```class SP_ConditionalOP
{
public static void main(String[] args)
{
double d1=7.95,d2=15.90;
boolean x=(2*d1==15.90 && d2/2==7.95);
boolean y=(2*d1==15.90 || d2/2==7.95);
boolean z=(x || y);
System.out.println(z);
}
}```

Quizzes

Operator Precedence Quiz #3742

Code Sheets:12  Exam Paper Problems:8  Solved Problems:5  Quizzes:6
×