友情提示:如果本网页打开太慢或显示不完整,请尝试鼠标右键“刷新”本网页!阅读过程发现任何错误请告诉我们,谢谢!! 报告错误
一世书城 返回本书目录 我的书架 我的书签 TXT全本下载 进入书吧 加入书签

Java编程思想第4版[中文版](PDF格式)-第39章

按键盘上方向键 ← 或 → 可快速上下翻页,按键盘上的 Enter 键可回到本书目录页,按键盘上方向键 ↑ 可回到本页顶部!
————未阅读完?加入书签已便下次继续阅读!




内容。  

  

//: AllOps。java  

// Tests all the operators on all the  

// primitive data types to show which  

// ones are accepted by the Java piler。  

  

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  1;  

    //! x = x 》》》 1;  

    // pound assignment:  

    //! x += y;  

    //! x …= y;  

    //! x *= y;  

    //! x /= y;  

    //! x %= y;  

    //! 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  1);  

    x = (char)(x 》》》 1);  

    // pound assignment:  

    x += y;  

    x …= y;  

    x *= y;  

    x /= y;  

    x %= y;  

    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  1);  

    x = (byte)(x 》》》 1);  

    // pound assignment:  

    x += y;  

    x …= y;  

    x *= y;  

    x /= y;  

    x %= y;  

    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  1);  

    x = (short)(x 》》》 1);  

    // pound assignment:  

    x += y;  

    x …= y;  

    x *= y;  

    x /= y;  

    x %= y;  

    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  1;  

    x = x 》》》 1;  

    // pound assignment:  

    x += y;  

    x …= y;  

    x *= y;  

    x /= y;  

    x %= y;  

    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  1;  

    x = x 》》》 1;  

    // pound assignment:  

    x += y;  

    x …= y;  

    x *= y;  

    x /= y;  

    x %= y;  

    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;  

    int i = (int)x;  

    float f = (float)x;  

    double d = (double)x;  

  }  

  void floatTest(float x; float y) {  

    // Arithmetic operators:  

    x = x * y;  

    x = x / y;  

    x 
返回目录 上一页 下一页 回到顶部 0 0
未阅读完?加入书签已便下次继续阅读!
温馨提示: 温看小说的同时发表评论,说出自己的看法和其它小伙伴们分享也不错哦!发表书评还可以获得积分和经验奖励,认真写原创书评 被采纳为精评可以获得大量金币、积分和经验奖励哦!