Differences between preface and postfix of operators

There are two types of addition and subtraction operators, preface and postfix, each with different behavior.

--In the case of postscript Calculate after doing something

b = a++;
// b = a;
// a = a + 1;
//Same as

--Introduction Do something after calculating

b = ++a;
// a = a + 1;
// b = a;
//Same as

For example, when used in print ()

--After: Calculate after output --Before: Calculate and then output

become.

operator.java


public class operator{
   public static void main(String[], args){

      i = 5;
      countdown1(i); // 54321
      
      System.out.println();
      i = 5;
      countdown2(i); // 43210
   }


   void countdown1(int i){
      for(i > 0){
         System.out.print(i--); //Output and then subtract
         countdown1(i);
      }
   }


   void countdown2(int i){
      for(i > 0){
         System.out.print(--i); //Subtract and then output
         countdown2(i);
      }
   }
}

Recommended Posts

Differences between preface and postfix of operators
Differences between IndexOutOfBoundsException and ArrayIndexOutOfBoundsException
Differences between "beginner" Java and Kotlin
Differences between Applet class and JApplet class
[Rails] Differences and usage of each_with_index and each.with_index
Differences between Java and .NET Framework
Difference between isEmpty and isBlank of StringUtils
[Java] Differences between instance variables and class variables
Difference between addPanel and presentModally of FloatingPanel
Differences between Ruby strings and symbols [Beginner]
Get a rough idea of the differences between protocols, classes and structs!
Differences between Spring Initializr packaging JAR and WAR
[Understanding] Differences between hashes and arrays in Ruby
Differences between Java, C # and JavaScript (how to determine the degree of obesity)
Summarize the differences between C # and Java writing
Difference between member and collection of rails routes.rb
Ruby: Differences between class methods and instance methods, class variables and instance variables
[Ruby] Difference between receiver and object. Differences between Ruby objects and JS objects
Differences between Ruby syntax error statements in Ruby and binary
Behavior is different between new and clear () of ArrayList
Differences between browser sessions and cookies and Rails session and cookies methods
Verification of the relationship between Docker images and containers
Differences between Fetch Type LAZY and EAGER in Hibernate
Comparison operators and conditionals
Evaluation of logical operators
Switch between JDK 7 and JDK 8
Difference between vh and%
Difference between i ++ and ++ i
Basic operators and operations
[Java Bronze learning] Differences between encapsulation, data hiding, and information hiding
[Docker-compose] Difference between env_file and environment. Priority of environment variable application
[Rails] Differences between redirect_to and render methods and how to output render methods
[Ruby] About the difference between 2 dots and 3 dots of range object.
[Java] Difference between assignment of basic type variable and assignment of reference type variable
Think about the differences between functions and methods (in Java)
Differences in how to handle strings between Java and Perl
[Java] Difference between Stack Overflow Error and Out Of Memory Error