Java Programing laungage

Core Java Tutorial

Introduction of Core Java

How To Install JDk and Set of Path

Syntax of java Program

Difference between Java and C/C++

Advantage and Disadvantage of Java

What is Java

Why Java is not Pure Object Oriented Language

Java has Following Features/Characteristics

Limitation of Java Language and Java Internet

Common Misconception about Java

Simple Program of Java

Integrated Development Environment in java

Compile and Run Java Program

Applet and Comments in Java

Tokens in Java

Keywords in Java

Identifier and Variables in Java

Literals/Constants

Data Type in Java

Assignments and Initialization in Java

Operators in Java

Rule of Precedence in Java

Operator on Integer and Separators in Java Programming

Java Control Flow of Statements

If and If-else Selection Statement

Nested If-else and If-else-If Selection Statement

switch case and conditional operator Selection Statement

for and while Loop

do..while and for each Loop

break and labeled break statement

continue and labeled continue statement

return Statement and exit() Method

Escape Sequence for Special Characters and Unicode Code

Constants and Block or Scope

Statement in Java

Conversions between Numeric Types in Java

Import Statement in Java

User Input in Java using Scanner Class

User Input in Java using Console Class

Array in Java

One Dimensional Array

Two Dimensional Array

Two Dimensional Array Program

Command Line Argument in Java

String args Types in Java

Uneven/Jagged array in java

Math Class Function and Constant

Math Class all Function used in a program

Enumerated Types in Java

Object Oriented Programming v/s Procedural Programming

Object Oriented Programming Concepts in Java

Introduction to Class,Object and Method in Java

Class Declaration in Java

Class & Objects in java

Encapsulation in Java

Modifiers/Visibility for a Class or Interrface or member of a Class

Polymorphism in Java

Runtime polymorphism (dynamic binding or method overriding)

Operators ,Increment and Decrement Operators
Previous Home Next

The basic arithmetic operators +, , *, / are used in Java for addition, subtraction, multiplication and division. The / operator denotes integer division if both arguments are integers, and floating-point division otherwise.

The mod function is denoted by %. For example, 19 / 2 is 9, 21 % 2 is 1, and 7.0 / 2 is 3.5.Note that integer division by 0 raises an exception, whereas floating-point division by 0 yields an infinite result.You can use the arithmetic operators in your variable initializations:


int p = 9
int q = 2 * p;  // The value of q is 18

There is a convenient shortcut for using binary arithmetic operators in an assignment.

Example


p += 4;
is equal to
p = p + 4;

One of the most common operations with a numeric variable is to increment or decrement it value by 1. Java like in C and C++, has both increment and decrement operators: p++ adds 1 to the current value of the variable p, and p-- subtracts 1 from it.


int  = 6;
p++;

changes p to 7. Because these operators change the value of a variable, they cannot be applied to numbers themselves. For example, 7++ is not a legal statement in java.

There are two forms of these operators, in above examples we have seen the postfix form of the operator that is placed after the operand. There is also a prefix form, ++p. Both change the value of the variable by 1. But there is difference between the two and can only appear when they are used inside expressions. The prefix form does the addition first, the postfix form evaluates to the old value of the variable.


int p = 3;
int q = 3;
p++;
++q;
int x = 4 * p;    // x  is 12, p is 8
int y = 4 * q;   // y is 16, q is 8

Previous Home Next

Tolal:0 Click:

Show All Comments

Did not find what you were looking for leave your name and message. We will revert within 24 hours
Name:
eMail:
Comment / Feedback: