Write a Java program to print Pre Decrement operation?

Write a Java program to print Pre Decrement operation


class Main
{
    public static void main(String args[])
    {
        int x=10;
        System.out.println("The PreDecrement value is "+(--x));
    }
}	
                                            

Output:

The PreDecrement value is 9




Using commandLine arguments

class Main
{
    public static void main(String args[])
    {
        int x;
        x=Integer.parseInt(args[0]);
        System.out.println("The PreDecrement value is "+(--x));
    }
}
                                            

Output:

The PreDecrement value is 9




Using Scanner class

import java.util.*;
class Main
{
    public static void main(String args[])
    {
        int x;
        Scanner s=new Scanner(System.in);
        System.out.println("Enter x value ");
        x=s.nextInt();
        System.out.println("The PreDecrement value is "+(--x));
}
}
                                            

Output:

Enter x value 10
The PreDecrement value is 9







More Programs


4 . PreDecrement Program
5 . PostDecrement Program
6 . Addition Program
7 . Substraction Program
8 . Multiplication Program
9 . Division Program
10 . Modular Division Program
11 . Swaping Of Two Numbers With Using Third Variable
12 . Swaping Of Two Numbers Without Using Third Variable
13 . Relation Of Two Numbers Program using > < <= >= !=
14 . Logical Operators Program using &&, || ,!