码迷,mamicode.com
首页 > 编程语言 > 详细

Java运算符——2017.08.01

时间:2017-08-01 20:41:33      阅读:139      评论:0      收藏:0      [点我收藏+]

标签:stat   package   float   大于   ++   tor   操作   ble   main   

技术分享

 

package Collection;
//除法运算与求余运算的区别 public class Div { public static void main(String[] args) { // TODO Auto-generated method stub int int1=5; int int2=2; double double1=2.0; //除法运算结果 System.out.println(int1/int2); System.out.println(int1/double1); /* * 2 * 2.5 */ //%求余运算 System.out.println(int1%2); System.out.println(double1%0);//NaN:非数 } }

  

package Collection;

//++a与a++的区别
public class LeiJia {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
    int a=10;
    System.out.println(a++);
    System.out.println(a);
    System.out.println(++a);
		   
	}
}
  // 10
       // 11
      // 12

  

package Collection;

// 比较运算符
public class Bijiao {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int int1=453;
		float float1=453f;
		System.out.println(int1==float1);

		
		//==,两边只能是数值类型,只要数值相等,数据类型可以不同
		//输出true
	}

}

  

package Collection;

public class LogicOperator {

	public static void main(String[] args) {
		// TODO Auto-generated method stub

		int a=5;
		int b=6;
		int c=8;
		// &&与&的比较
//	    if (a>3 && b++>4)
//		{
//			System.out.println(a+"   "+b);
//		}
//		// 此处输出结果 a=5   b=7
//		if (a>4 & ++c>2)
//		{
//			System.out.println(a+"   "+c);
//		}
//		//5   9
//		
		
	   // ||和|的比较
		
//		if(a>3 || c++>3)
//		{
//			System.out.println(a+"  "+c);
//		}
//		 //输出结果:5  8
		
		if(a>3 | c++>3)
		{
			System.out.println(a+"  "+c);
		}
		//输出结果5  9
	}
      

}

 //   &&与&的区别,||与|的区别一样,以后者为例子来说明,当|只要两个操作数(前操作数与后操作数),前操作数是true,后操作数不会运算,而||不管前操作数是否位true,后操作数都会运算。

package Collection;

public class Threecharacters {

	//三目运算符
	public static void main(String[] args) {
      int a=11;
      int b=12;
      System.out.println(a<b ? "a小于b" : "a大于b");
      
//三目运算符形式是:(expression) ? if-true-statement : if-false-statement

	}

}

  

Java运算符——2017.08.01

标签:stat   package   float   大于   ++   tor   操作   ble   main   

原文地址:http://www.cnblogs.com/linjingjia/p/7270186.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!