网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.java中字符转换.
.Java中使用DirectDraw.
.JDBMonitor在多数据源中的问题.
.java日记:学习java一年体会4.
.基于Eclipse 3.0的SWT编程.
.J2EE中用RMI和CORBA进行分布式Ja.
.幸福的联姻:Java和Python.
.FCKeditor编辑器在JAVA中的使用与.
.用Java实现Hello World.
.Java正则表达式详解.
.设计模式在EJB中的应用(3).
.JDBC连接数据库经验集萃.
.Java写的查找重复电话号码程序.
.getItem 方法.
.Java技巧:用Java实现回调例程.
.《实时UML与Rational Rose RealT.
.What is AspectJ.
.介绍关于UI管理器的设计(草案)方.
.使用Sets.
.使用logic:iterate遇到的问题.

Java运算符总结

发表日期:2008-1-5



  运算符总结
  下面这个例子向大家展示了如何随同特定的运算符使用主数据类型。从根本上说,它是同一个例子反反复复地执行,只是使用了不同的主数据类型。文件编译时不会报错,因为那些会导致错误的行已用//!变成了注释内容。
  //: AllOps.Java
  // Tests all the operators on all the
  // primitive data types to show which
  // ones are accepted by the Java compiler.
  
  class AllOps {
   // To accept the results of a boolean test:
   void f(boolean b) {}
   void boolTest(boolean x, boolean y) {
    // Arithmetic operators:
    //! x = x * y;
    //! x = x / y;
    //! x = x % y;
    //! x = x + y;
    //! x = x - y;
    //! x++;
    //! x--;
    //! x = +y;
    //! x = -y;
    // Relational and logical:
    //! f(x > y);
    //! f(x >= y);
    //! f(x < y);
    //! f(x < = y);
    f(x == y);
    f(x != y);
    f(!y);
    x = x && y;
    x = x y;
    // Bitwise operators:
    //! x = ~y;
    x = x & y;
    x = x y;
    x = x ^ y;
    //! x = x < < 1;
    //! x = x >> 1;
    //! x = x >>> 1;
    // Compound assignment:
    //! x += y;
    //! x -= y;
    //! x *= y;
    //! x /= y;
    //! x %= y;
    //! x < < = 1;
    //! x >>= 1;
    //! x >>>= 1;
    x &= y;
    x ^= y;
    x = y;
    // Casting:
    //! char c = (char)x;
    //! byte B = (byte)x;
    //! short s = (short)x;
    //! int i = (int)x;
    //! long l = (long)x;
    //! float f = (float)x;
    //! double d = (double)x;
   }
   void charTest(char x, char y) {
    // Arithmetic operators:
    x = (char)(x * y);
    x = (char)(x / y);
    x = (char)(x % y);
    x = (char)(x + y);
    x = (char)(x - y);
    x++;
    x--;
    x = (char)+y;
    x = (char)-y;
    // Relational and logical:
    f(x > y);
    f(x >= y);
    f(x < y);
    f(x < = y);
    f(x == y);
    f(x != y);
    //! f(!x);
    //! f(x && y);
    //! f(x y);
    // Bitwise operators:
    x= (char)~y;
    x = (char)(x & y);
    x = (char)(x y);
    x = (char)(x ^ y);
    x = (char)(x < < 1);
    x = (char)(x >> 1);
    x = (char)(x >>> 1);
    // Compound assignment:
    x += y;
    x -= y;
    x *= y;
    x /= y;
    x %= y;
    x < < = 1;
    x >>= 1;
    x >>>= 1;
    x &= y;
    x ^= y;
    x = y;
    // Casting:
    //! boolean b = (boolean)x;
    byte B = (byte)x;
    short s = (short)x;
    int i = (int)x;
    long l = (long)x;
    float f = (float)x;
    double d = (double)x;
   }
   void byteTest(byte x, byte y) {
    // Arithmetic operators:
    x = (byte)(x* y);
    x = (byte)(x / y);
    x = (byte)(x % y);
    x = (byte)(x + y);
    x = (byte)(x - y);
    x++;
    x--;
    x = (byte)+ y;
    x = (byte)- y;
    // Relational and logical:
    f(x > y);
    f(x >= y);
    f(x < y);
    f(x < = y);
    f(x == y);
    f(x != y);
    //! f(!x);
    //! f(x && y);
    //! f(x y);
    // Bitwise operators:
    x = (byte)~y;
    x = (byte)(x & y);
    x = (byte)(x y);
    x = (byte)(x ^ y);
    x = (byte)(x < < 1);
    x = (byte)(x >> 1);
    x = (byte)(x >>> 1);
    // Compound assignment:
    x += y;
    x -= y;
    x *= y;
    x /= y;
    x %= y;
    x < < = 1;
    x >>= 1;
    x >>>= 1;
    x &= y;
    x ^= y;
    x = y;
    // Casting:
    //! boolean b = (boolean)x;
    char c = (char)x;
    short s = (short)x;
    int i = (int)x;
    long l = (long)x;
    float f = (float)x;
    double d = (double)x;
   }
   void shortTest(short x, short y) {
    // Arithmetic operators:
    x = (short)(x * y);
    x = (short)(x / y);
    x = (short)(x % y);
    x = (short)(x + y);
    x = (short)(x - y);
    x++;
    x--;
    x = (short)+y;
    x = (short)-y;
    // Relational and logical:
    f(x > y);
    f(x >= y);
    f(x < y);
    f(x < = y);
    f(x == y);
    f(x != y);
    //! f(!x);
    //! f(x && y);
    //! f(x y);
    // Bitwise operators:
    x = (short)~y;
    x = (short)(x & y);
    x = (short)(x y);
    x = (short)(x ^ y);
    x = (short)(x < < 1);
    x = (short)(x >> 1);
    x = (short)(x >>> 1);
    // Compound assignment:
    x += y;
    x -= y;
    x *= y;
    x /= y;
    x %= y;
    x < < = 1;
    x >>= 1;
    x >>>= 1;
    x &= y;
    x ^= y;
    x = y;
    // Casting:
    //! boolean b = (boolean)x;
    char c = (char)x;
    byte B = (byte)x;
    int i = (int)x;
    long l = (long)x;
    float f = (float)x;
    double d = (double)x;
   }
   void intTest(int x, int y) {
    // Arithmetic operators:
    x = x * y;
    x = x / y;
    x = x % y;
    x = x + y;
    x = x - y;
    x++;
    x--;
    x = +y;
    x = -y;
    // Relational and logical:
    f(x > y);
    f(x >= y);
    f(x < y);
    f(x < = y);
    f(x == y);
    f(x != y);
    //! f(!x);
    //! f(x && y);
    //! f(x y);
    // Bitwise operators:
    x = ~y;
    x = x & y;
    x = x y;
    x = x ^ y;
    x = x < < 1;
    x = x >> 1;
    x = x >>> 1;
    // Compound assignment:
    x += y;
    x -= y;
    x *= y;
    x /= y;
    x %= y;
    x < < = 1;
    x >>= 1;
    x >>>= 1;
    x &= y;
    x ^= y;
    x = y;
    // Casting:
    //! boolean b = (boolean)x;
    char c = (char)x;
    byte B = (byte)x;
    short s = (short)x;
    long l = (long)x;
    float f = (float)x;
    double d = (double)x;
   }
   void longTest(long x, long y) {
    // Arithmetic operators:
    x = x * y;
    x = x / y;
    x = x % y;
    x = x + y;
    x = x - y;
    x++;
    x--;
    x = +y;
    x = -y;
    // Relational and logical:
    f(x > y);
    f(x >= y);
    f(x < y);
    f(x < = y);
    f(x == y);
    f(x != y);
    //! f(!x);
    //! f(x && y);
    //! f(x y);
    // Bitwise operators:
    x = ~y;
    x = x & y;
    x = x y;
    x = x ^ y;
    x = x < < 1;
    x = x >> 1;
    x = x >>> 1;
    // Compound assignment:
    x += y;
    x -= y;
    x *= y;
    x /= y;
    x %= y;
    x < < = 1;
    x >>= 1;
    x >>>= 1;
    x &= y;
    x ^= y;
    x = y;
    // Casting:
    //!
上一篇:工作流引擎 人气:1739
下一篇:用构建器自动初始化 人气:496
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐