Files
javaSE260715/day02/src/com/inmind/yunsuan02/Demo07.java

45 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.yunsuan02;
/**
算数运算符:++(自增) --(自减)
++(自增):表示在当前的基础上+1
--(自减):表示在当前的基础上-1
使用方式有2种
1.独立使用 (++在前还是在后,没有区别)
变量++ ++变量
2.组合使用(赋值的形式)
定义一个变量
变量 = ++i 变量 = i++
j = i++; 后增:先进行运算,再执行自增
j = ++i; 前增:先进行自增,再执行运行
*/
public class Demo07 {
public static void main(String[] args) {
//定义整型变量
int i = 10;
//1.自增独自使用,将自己+1赋值给自己
//ctrl+/ :注释一行
// i++;
++i;
System.out.println(i);
System.out.println("---------------");
//2.组合使用
int j = 10;
int k;//先定义变量,后赋值
//j++,后增,在进行运算中,先进行运算,后执行自增
//k = j++;//k = j; j = j+1;
//++j,先增,在进行运算中,先进行自增,后进行运算
k = ++j;//j= j+1; k = j;
System.out.println(k);//11
System.out.println(j);//11
System.out.println("---------------");
int a = 10;
int b;
b = ++a + a-- + --a + a++;
System.out.println(b);//40
System.out.println(a);//10
}
}