


Detailed introduction to the java self-increment and self-decrement operation process
This article mainly introduces the java self-increment and self-decrement operation process. It is very good and has reference value. Friends who need it can refer to it.
No more nonsense, I will directly post the code for everyone. , the specific code is as follows:
public class Add { public static void main(String[] args) { int i = 0; i=i++ + ++i; int j = 0; j= ++j + j++ + j++ + j++; int k = 0; k=k++ + k++ + k++ + ++k; int h = 0; h=++h + ++h; int p1=0,p2=0; int q1=0,q2=0; q1=+p1; q2=p2++; System.out.println("i "+i); System.out.println("j "+j); System.out.println("k "+k); System.out.println("h "+h); System.out.println("p1 "+p1); System.out.println("p2 "+p2); System.out.println("q1 "+q1); System.out.println("q2 "+q2); } }
Output
i 2 j 7 k 7 h 3 p1 0 p2 1 q1 1 q2 0
Analysis: The difference between i++ and ++i is that one is the auto-increment after the program is completed, and the other is the auto-increment before the program starts. increase.
The execution process of "i=i++ + ++i" is to execute i++ first, but the operation of incrementing i by 1 is executed later, so i is still 0 at this time, and then ++i,++ is executed. The value of i after i is 1. After executing ++i, i++ must be added, so the value of i at this time is actually 2,0+2=2, and then assigned to i, the final value of i is 2.
"j= ++j + j++ + j++ + j++", the execution process is to first ++j, so the value of j is 1, and then execute j++. After j++, the value of j is still 1, and then execute j++, the result after execution is still 1, but the j++ just now needs to be supplemented, so the actual value of j at this time is 2, and then the last j++ is executed, the result after execution is still 2, but the j++ just now needs to be supplemented, So the value of j at this time is actually 3, so 1+1+2+3=7, and then assigned to j, the final value of j is 7.
“k=k++ + k++ + k++ + + +k" is executed by k++ first, so the value of k is 0, and then k++ is executed. After k++, the value of k is still 0, but the previous k++ needs to be supplemented, so the value of k is actually 1 at this time, and then Execute the last k++ again, and the result after execution is still 1, but the previous k++ needs to be supplemented, so the value of K is actually 2 at this time. Finally, ++k is executed, and the execution result is 3. Then the previous k++ is supplemented. , the actual result of k is 4, so 0+1+2+4=7, and then assigned to k, the final value of k is 7.
"h=++h + ++h" is to increment h first, and the value of h is 1, and then increment it by itself. The value of h is 2, so 1+2=3, and then assign it to h. The final value of h is 3.
"q1=++p1" first increments p1, the value of p1 is 1, and then assigns it to q1, so the value of q1 is 1.
" q2=p2++" first assign p2 to q2, the value of q2 is 0, and then increment p2, so the value of p2 is 1.
The above is the detailed content of Detailed introduction to the java self-increment and self-decrement operation process. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Guide to Perfect Number in Java. Here we discuss the Definition, How to check Perfect number in Java?, examples with code implementation.

Guide to Random Number Generator in Java. Here we discuss Functions in Java with examples and two different Generators with ther examples.

Guide to Weka in Java. Here we discuss the Introduction, how to use weka java, the type of platform, and advantages with examples.

Guide to Smith Number in Java. Here we discuss the Definition, How to check smith number in Java? example with code implementation.

In this article, we have kept the most asked Java Spring Interview Questions with their detailed answers. So that you can crack the interview.

Java 8 introduces the Stream API, providing a powerful and expressive way to process data collections. However, a common question when using Stream is: How to break or return from a forEach operation? Traditional loops allow for early interruption or return, but Stream's forEach method does not directly support this method. This article will explain the reasons and explore alternative methods for implementing premature termination in Stream processing systems. Further reading: Java Stream API improvements Understand Stream forEach The forEach method is a terminal operation that performs one operation on each element in the Stream. Its design intention is

Guide to TimeStamp to Date in Java. Here we also discuss the introduction and how to convert timestamp to date in java along with examples.

Capsules are three-dimensional geometric figures, composed of a cylinder and a hemisphere at both ends. The volume of the capsule can be calculated by adding the volume of the cylinder and the volume of the hemisphere at both ends. This tutorial will discuss how to calculate the volume of a given capsule in Java using different methods. Capsule volume formula The formula for capsule volume is as follows: Capsule volume = Cylindrical volume Volume Two hemisphere volume in, r: The radius of the hemisphere. h: The height of the cylinder (excluding the hemisphere). Example 1 enter Radius = 5 units Height = 10 units Output Volume = 1570.8 cubic units explain Calculate volume using formula: Volume = π × r2 × h (4
