Java Second: arithmetic operators and expressions

Arithmetic Operators and expression

    Suddenly, we waved goodbye to 2019 has, 2020 Year of the Rat was with the spring tide rolling in. Not long ago, I was doing the second half of 2019 soft test (formerly known as: computer technology and software professional and technical qualification examinations) junior programmers test questions in the afternoon, I was in that place still a little confused, I find time to put down the test sites there again a review. I believe there are many small partners of this place is full of doubt, where Marshal unity to everyone for their answers:
    the subject is such that knowledge mainly on the arithmetic operators and expressions (soft test presentation of the C language, I use is Java, the question of principle is the same):

public class Study{
	public static void main(String args[]){
	int h1=6,h2,h3,h4=8;
		h3=h1;
		h2=h1++;
		System.out.println("h3="+h3+" h2="+h2+" h1="+h1);
		System.out.println("h4="+h4);
		System.out.print("h4="+ ++h4 +" ");
		System.out.println("h4="+h4);
		System.out.print("h4="+ --h4 +" ");
		System.out.println("h4="+h4);
		System.out.print("h4="+ h4++ +" ");
		System.out.println("h4="+h4);
		System.out.print("h4="+ h4-- +" ");
		System.out.println("h4="+h4);  
	}
}

The resulting output is:

h3=6 h2=6 h1=7
h4=8
h4=9 h4=9
h4=8 h4=8
h4=8 h4=9
h4=9 h4=8

to sum up:

++ h4 (or --h4) is used in the first operation, i.e. the value before the increment, or h4 decrement calculation again, h4 ++ (or h4--) and then used for the first operation, i.e., the value calculated prior h4 then increment or decrement once. If doubt, welcome message exchange.

Like a point, plus followers chant! Hey!

Published 30 original articles · won praise 72 · views 10000 +

Guess you like

Origin blog.csdn.net/H_W_1212/article/details/103991226