Use of ++ and – in java
++ is increment operator for increment by 1
And – is decrement operator for decrement by 1
Types of ++
There are two types of ++
Post increment : a++ here value of a is print first then increment is done
Example
Class postincrement
{
public static void main( string[] args)
{
Int a=10;
a++;
System.out.println(+a);
}
}
In above example we get output 10
If we take ++a( pre increment ) instead of a++ then we get output 11
There are two types of --
Post decrement : a-- here value of a is print first then decrement is done
++ is increment operator for increment by 1
And – is decrement operator for decrement by 1
Types of ++
There are two types of ++
Post increment : a++ here value of a is print first then increment is done
Example
Class postincrement
{
public static void main( string[] args)
{
Int a=10;
a++;
System.out.println(+a);
}
}
In above example we get output 10
If we take ++a( pre increment ) instead of a++ then we get output 11
Types of --
There are two types of --
Post decrement : a-- here value of a is print first then decrement is done
Example
Class postdecrement
{
public static void main( string[] args)
{
Int a=10;
a--;
System.out.println(+a);
}
}
In above example we get output 10
If we take --a( pre decrement ) instead of a-- then we get output 9
Class postdecrement
{
public static void main( string[] args)
{
Int a=10;
a--;
System.out.println(+a);
}
}
In above example we get output 10
If we take --a( pre decrement ) instead of a-- then we get output 9
No comments:
Post a Comment