Increment Decrement Operators Program in Java
public class JavaIncrementDecrementOperator
{
public static void main(String[] args)
{
int i=10,j=10,num=0;
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("num="+num);
System.out.println("---------------------------------------");
i++;
j--;
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("num="+num);
System.out.println("---------------------------------------");
num=i++;
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("num="+num);
System.out.println("---------------------------------------");
num=i++ + ++i;
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("num="+num);
System.out.println("---------------------------------------");
num=i++ + --j;
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("num="+num);
System.out.println("---------------------------------------");
num=--i + j++;
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("num="+num);
System.out.println("---------------------------------------");
num=++i + ++j;
System.out.println("i="+i);
System.out.println("j="+j);
System.out.println("num="+num);
}
}
Output:
i=10 j=10 num=0 --------------------------------------- i=11 j=9 num=0 --------------------------------------- i=12 j=9 num=11 --------------------------------------- i=14 j=9 num=26 --------------------------------------- i=15 j=8 num=22 --------------------------------------- i=14 j=9 num=22 --------------------------------------- i=15 j=10 num=25b. tech. bca icse java java tutorials learn java mca programs