India's Largest Free Online Education Platform

Increment operator in java

Increment operator in java

Code:

import java.util.Scanner;
public class Increment_Operator
{
    public static void main(String args[])
    {
        System.out.println("Enter a number");
        Scanner Sc= new Scanner(System.in);
        int x= Sc.nextInt();
        System.out.println("You entered: "+x);
        // Now pre and post increment-
        System.out.println("Post-incremneted value is: "+ x++);
        x--;
        System.out.println("Pre-incremneted value is: "+ ++x);
    }
}

Output:

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!