JAVA ASSIGNMENT HELP USA | JAVA HOMEWORK HELP USA | JAVA PROJECT HELP USA | JAVA HELP USA | ONLINE JAVA HELP

In **Java programming** operator play an important role. Students of Yale university feel problem in implementation of operator in **Java Programming**. During **Java Programming projects** operator play very vital role. So, operator is an image which play out an operation.

An administrator is said to be unary, on the off chance that it performs operation on single operand.

Ex:

int a = 10;

a++;

An administrator is said to be paired, on the off chance that it performs operation on two operands

Ex:

int a=10, b=20;

int c = a-b;

An Operator is said to be ternary on the off chance that it perform operation on three operands

Ex:

int a = 10, b=20, c;

c= (a>b) ? a : b;

Administrators in java are isolated into 4 noteworthy classifications

Number juggling

Restrictive

Sensible

Bitwise

other operators like (task, comma, and so on.,)

Arithmetic Operators

Operator Performs

+ Additon (also used for String concatenation)

- Subtraction

/ Division

* Multiplication

% Gives Remainder

++ Pre or post increment

-- Pre or post decrement

class ArithmeticOperation{

public static void main(String args[]){

int operand1 = 30;

int operand2 = 10;

System.out.println("Addition of operand1 and operand2 is " + (operand1 + operand2));

System.out.println("Subtraction of operand1 and operand2 is " + (operand1 - operand2));

System.out.println("Multiplication of operand1 and operand2 is " + (operand1 * operand2));

System.out.println("Division of operand1 and operand2 is " + (operand1 / operand2));

System.out.println("Remainder of operand1 and operand2 is " + (operand1 % operand2));

}

}

Output

Addition of operand1 and operand2 is 40

Subtraction of operand1 and operand2 is 20

Multiplication of operand1 and operand2 is 300

Division of operand1 and operand2 is 3

Remainder of operand1 and operand2 is 0

Some points to be Noted

1. Multiplication, Division and remainder operators has more priority than Addition and Subtraction operators.

Example

class ArithmeticPriority{

public static void main(String args[]){

int var1 = 10, var2 = 20;

int result = var1+var2*var1;

System.out.println(result);

result = var1-var2/var1;

System.out.println(result);

result = var1+var2%var1;

System.out.println(result);

}

}

Output

210

8

10

Explanation

for the Expression

result = var1+var2*var1

= 10 + 20*10

= 10 +200

= 210

result = var1-var2/var1

= 10-20/10

= 10-2

= 8

result = var1+var2%var1

= 10 + 20 % 10

= 10 + 0

= 10

2. Remainder operator always returns the sign of numerator

Ex:

5 % 2 = 1

-5 % 2 = -1

class RemainderEx{

public static void main(String args[]){

int var1 = 25, var2 = 10;

System.out.println(var1%var2);

var1= -25;

System.out.println(var1%var2);

}

}

Arithmetic Operators: ++, --

++ Increment operator; increments a value by 1

-- Decrement operator; decrements a value by 1

Pre increment

Syntax:

++variable

pre increment operator increments the variable value by 1 immediately.

Example

class PreIncrement{

public static void main(String args[]){

int var = 10;

System.out.println(++var);

}

}

Output

11

Post increment

Syntax:

variable++

post increment operator increments the variable value by 1 after executing the current statement.

class PostIncrement{

public static void main(String args[]){

int var = 10;

System.out.println(var++);

System.out.println(var);

}

}

Output

10

11

Pre Decrement

Syntax:

--variable

pre decrement operator decrements the variable value by 1 immediately.

Example

class PreDecrement{

public static void main(String args[]){

int var = 10;

System.out.println(--var);

}

}

Output

9

Post Decrement

Syntax:

variable--

post decrement operator decrements the variable value by 1 after executing the current statement.

class PostIncrement{

public static void main(String args[]){

int var = 10;

System.out.println(var--);

System.out.println(var);

}

}

Output

10

9

Some more Examples

Class ArithmeticEx{

public static void main(String args[]){

int var = 10;

int result = var++ + var++ ;

System.out.println("value of variable is " + var);

System.out.println("Result is " +result);

result = var++ + ++var;

System.out.println("value of variable is " + var);

System.out.println("Result is " +result);

result = var++ + var--;

System.out.println("value of variable is " + var);

System.out.println("Result is " +result);

result = --var + var--;

System.out.println("value of variable is " + var);

System.out.println("Result is " +result);

}

}

Output

value of variable is 12

Result is 21

value of variable is 14

Result is 26

value of variable is 14

Result is 29

value of variable is 12

Result is 26

We have 2500+ expert pool from all over the world. They are highly qualified and well experienced. All experts have experinced in teaching and good command over programming topics. Some of our experts are as follows: