package unary_operator;
import org.junit.Test;
/*一元运算符:前++ 后++*/
public class UnaryOperatorTest {
@Test
public void test() {
int i = 3;
//i=3 4 5
int k = (i++) + (i++) + (i++);
System.out.println(k);//12
i=3;
//i=4 5 6
k = (++i) + (++i) + (++i);
System.out.println(k);//15
i = 1;
//i=1 3 3 1
k = (i++) + (++i) + (i--) + (--i);
System.out.println(k);//8
}
@Test
public void test1() {
int n=1,m=1;
int sum = (n++)+(++n)+(m++)+(++m)+
(n++)+(++m)+(n++)+(n++);
//n=1 n=3 n=3 n=4 n=5
//m=1 m=3 m=4
System.out.println(sum);
}
@Test
public void test2(){
int n=0,m=0,k=0,j=0;
k = n++; //k==0 n=1
++n;//n=2
++m;//m=1
n++;//n=3
--n;//n=2
m++;//m=2
--m;//m=1
m++;//m=2
//m=2 2 3
//n=3 3 4
//j=7+10=17
j=(m++)+(++n)+(--m)+(++m)+(n++)+(n++);
System.out.println(m);
System.out.println(n);
System.out.println(k);
System.out.println(j);
}
@Test
public void test3(){
int m=0,n=0;
//m=1 2 2 2 2 4 4 6 6 8
System.out.println((++m)+(++m)
+(m--)+(++m)+(m++)+(++m)
+(m++)+(++m)+(m++)+(++m));//37
//n=0 2 2
//m=7
System.out.println((n++)+(--m)
+(++n)+(n++));//11
System.out.println(n);//3
System.out.println(m);//7
}
}
标签:一元,++,System,运算符,--,int,println,out
From: https://www.cnblogs.com/haveanicedayfh/p/17115812.html