Files
javaSE-260914/day02/src/com/inmind/operator02/Demo07.java
T

59 lines
1.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
package com.inmind.operator02;
/*
算术运算中的++ --
++ 表示在当前的基础+1
-- 表示在当前的基础-1
他们是针对变量来操作
变量++,++变量
他们的使用有2种方式:
1.独立使用
++,--在独立使用时没有区分
案例:
i++;
System.out.println(i);
++i;
System.out.println(i);
2.组合使用
变量++:后增
++变量:先增
j = i++; 后增:先进行运算,再进行自增
j = ++i; 先增:先进行自增,再进行运算
*/
public class Demo07 {
public static void main(String[] args) {
int i = 10;
//1.独立使用
// i++;
++i;
System.out.println(i);//11
//2.组合使用
int j;
//后增:先进行运算,再进行自增
/* j = i++;//j = i; i = i + 1;
System.out.println("i的值为:"+i);//12
System.out.println("j的值为:"+j);//11*/
//先增:先进行自增,再进行运算
j = ++i;//i = i+1; j = i;
System.out.println("i的值为:"+i);//12
System.out.println("j的值为:"+j);//12
//随意出题:
int a = 10;
int b = 5;
int sum = a++ + ++ b + a++ + b++;
//int sum1 = a-- + -- b + a++ + b++;
System.out.println(sum);//33
System.out.println(a);//12
System.out.println(b);//7
}
}