Java基本运算

时间:2021-02-27 13:16:43   收藏:0   阅读:0

运算符

进阶运算

自增(++)自减(--)运算

public class Demo{
	
    public static void main(String[] args){
		
        //++   --  自增. 自减  一元运算符
        int a = 3;
        
        int b = a++;			//自增(++)在后面, 先赋值再自增运算
        
        System.out.println(a);	//输出结果为4
        System.out.println(b);	//输出结果为3
        
        int c = ++a;			//自增(++)在前面, 先自增运算再赋值
        
        System.out.println(a);	//输出结果为5
        System.out.println(c);	//输出结果为5
        
    }
}

数学运算(Math类)

public class Demo{
	
    public static void main(String[] args){
		
        //幂运算2^3    2*2*2=8
        double pow = Math.pow(2,3);
        System.out.println(pow);		//输出结果为8
        
        //更多运算与此类似, 自行百度
    }
}
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!