`

java编程思想笔记(三)运算符+控制程序流程

阅读更多

1 .java运算符总结

 

   编译会错的都加了//

public 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 bl = (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 bl = (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 bl = (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 bl = (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:
    //! boolean bl = (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 = 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 bl = (boolean)x;
    char c = (char)x;
    byte b = (byte)x;
    short s = (short)x;
    int i = (int)x;
    long l = (long)x;
    double d = (double)x;
  }
  void doubleTest(double x, double 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 bl = (boolean)x;
    char c = (char)x;
    byte b = (byte)x;
    short s = (short)x;
    int i = (int)x;
    long l = (long)x;
    float f = (float)x;
  }
}

 

2.控制语句(部分的详细不解释)

if-else

while

do-while 无论条件是否成立,都会运行一次do

for

break  continue 可以跳到指定标签 如 :

 

               outer:
		 for(int i=0;i<5;i++){
			if(i==3){
				continue outer;//跳到outer位置
			}
		}

 

 

开关 (swich) 要求使用一个选择因子,并且必须是 int 或 char 那样的整数值  

 

 

 

分享到:
评论

相关推荐

    Java编程思想读书笔记.doc

    ### Java编程思想读书笔记知识点梳理 #### 第1、2章:万事万物皆对象 ##### 一、所有对象都必须由你建立 - **存储位置**: - **寄存器**:程序中不可控。 - **栈 (Stack)**:存放基本类型数据和对象引用,对象...

    Java编程思想读书笔记

    《Java编程思想读书笔记》 Java是一门面向对象的编程语言,它的核心理念是“万事万物皆对象”。在Java中,所有的对象都是通过类(Class)来定义的,并且必须由程序员显式创建。理解对象的存储位置是理解Java内存...

    Java编程思想重点笔记(Java开发必看).pdf

    以上只是Java编程思想笔记中的冰山一角,深入学习还包括网络编程、数据库连接、JVM内存模型、垃圾回收机制、并发编程高级话题、Spring框架等内容。这些知识点构成了Java开发者必备的基础知识体系,通过不断学习和...

    java编程思想读书笔记.rar

    《Java编程思想》是 Bruce Eckel 的经典之作,这本书深入浅出地介绍了Java语言的核心概念和技术,对于初学者和有经验的程序员来说都是极好的学习资源。以下是对书中的主要知识点进行的详细解读: 1. **Java语言基础...

    非常好的java笔记适合初学者

    总的来说,这份"非常好的java笔记"是初学者学习Java编程的理想教材,它将引导读者逐步掌握编程基础,理解面向对象编程思想,以及熟悉Java特性和库的使用。通过系统的阅读和实践,初学者能够建立起坚实的Java编程基础...

    达内JAVA培训综合笔记

    面向对象是Java编程的核心思想,笔记中对类、对象、包、方法及其调用、引用、访问控制、构造器、继承、接口等概念都进行了深入讲解。特别是继承和多态的概念,是理解Java面向对象程序设计的关键。此外,还涵盖了抽象...

    大佬的java笔记

    由于提供的文件内容中,...如果要学习Java,最好的方式是从学习Java的基础语法和面向对象编程思想入手,逐步深入到类库使用和Java高级特性,同时实践相关的设计模式和架构设计,这样可以更全面地掌握Java编程的精髓。

    java学习笔记(全)

    首先,笔记可能从Java语言的基础开始讲解,包括变量、数据类型、运算符、流程控制(如if语句、switch语句、循环)、方法、数组等基本元素。这些是所有编程语言的基础,理解和掌握它们对于后续的学习至关重要。 接着...

    Java JDK 6学习笔记——ppt简体版

    Java JDK 6学习笔记是为Java初学者量身定制的一份宝贵资料,它涵盖了Java编程的基础概念、语法以及核心特性。这份PPT简体版旨在帮助读者快速掌握Java开发的基本技能,逐步成为一名合格的Java程序员。 Java JDK...

    《Java编程思想》学习笔记1(操作符、控制语句、对象、初始化与清理).doc

    ### Java编程思想学习笔记知识点...以上是《Java编程思想》学习笔记中关于操作符、控制语句、对象、初始化与清理等关键知识点的总结。通过理解这些基础概念和技术细节,可以更好地掌握 Java 编程的核心原理和技术实践。

    JAVA经典教材笔记

    - Java作为一种广泛使用的编程语言,其学习路径包括掌握基本语法、理解面向对象编程思想、熟悉标准库使用等。 - **JAVA发展概述** - Java的发展历程:从1995年由Sun Microsystems公司发布以来,Java经历了多次重大...

    达内1001java班课堂笔记

    在压缩包中的文件`sd1001_corejava_day01`,很可能包含了更详细的课堂讲解、代码示例或者练习,这部分内容可能涵盖了变量、数据类型、运算符、控制流程、数组、类和对象等Java基础知识。通过学习这些内容,学生可以...

    java私塾学习笔记整理

    ### Java私塾学习笔记整理 #### 第一章:Java入门 ...以上内容涵盖了Java基础知识的重要方面,从语言基础到高级特性,以及常见的开发技术和工具,帮助读者全面了解Java编程的基础知识和技术要点。

    Java学习笔记适合java初学者使用

    【Java学习笔记】是针对Java初学者的一套全面的学习资源,旨在帮助新手快速掌握Java编程基础知识。这份资料包含了丰富的学习内容,如Java语言的核心概念、语法特性、面向对象编程思想等,同时也融入了实践性的练习,...

    拉钩java高薪就业笔记.zip

    首先,笔记可能会从基础语法入手,包括变量、数据类型、运算符、流程控制语句(如if-else、switch、for、while)、函数的定义与调用等。这些都是Java编程的基础,理解并熟练运用这些知识点是成为一名合格Java开发者...

    良葛格java学习笔记

    接着,笔记会逐步讲解Java语法基础,如数据类型(基本类型和引用类型)、变量、运算符、流程控制语句(如if、for、while)、方法的定义与调用。此外,还会深入到类和对象的概念,这是面向对象编程的基础。初学者将...

Global site tag (gtag.js) - Google Analytics