Java #19: How to Increment/Decrement a Number in Java

//How to increment number
//pre-Increment variable
int preIncrement = 4;

//printing out pre-increment number to check
System.out.println(preIncrement);

//incrementing number
preIncrement++;

———————————————————————————
//How to Decrement by One

//Decrement Variable
int decrementVariable = 11;

//printing out decrementVariable to Check
System.out.println(decrementVariable);

//decreasing the variable decrementVariable
decrementVariable–;

//printing out the variable after decrementation(if that’s a word)
System.out.println(decrementVariable);


——————Both in one program—————–

//Programmer:Akinwale Owi
//Company:Dagba Computers
//Program Purpose:How to Create a Increment & Decrement in Java

package dagba.samples;

/**
*
* @author Akin
*/
public class DagbaSamples {

/**
* @param args the command line arguments
*/
public static void main(String[] args)
{
//pre-Increment variable
int preIncrement = 4;

//printing out pre-increment number to check
System.out.println(preIncrement);

//incrementing number
preIncrement++;

//printing out post increment number
System.out.println(preIncrement);

//Decrements Header
System.out.println(“——–Decrements——–“);

//Decrement Variable
int decrementVariable = 11;

//printing out decrementVariable to Check
System.out.println(decrementVariable);

//decreasing the variable decrementVariable
decrementVariable–;

//printing out the variable after decrementation(if that’s a word)
System.out.println(decrementVariable);

}//end of main

}//end of public Dagba Class

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.

Up ↑

%d bloggers like this: