提倡的程序风格 class point i intx, y ∥点的x轴、y轴坐标 Point(int x1,inty1){∥/构造方法 y= yI; Pointon ∥构造方法 this(0,0); void moveto(int x1,inty1){∥点移动到(x,y y=y1;
提倡的程序风格 class Point { int x, y; // 点的x轴、y轴坐标 Point(int x1, int y1) {// 构造方法 x = x1; y = y1; } Point(){ // 构造方法 this( 0, 0); } void moveto(int x1, int y1){ // 点移动到(x1, y1) x = x1; y = y1; } }
提倡的程序风格 class point ∥点的x轴、y轴坐标 Point(int xl,inty1)∥有参构造器 y= yI Point()/无参构造器 this(0,0); void moveto(intx1,inty1)∥点移动到(x1,y1) x=xI y=yI;
提倡的程序风格 class Point { int x, y; // 点的x轴、y轴坐标 Point(int x1, int y1) //有参构造器 { x = x1; y = y1; } Point( ) //无参构造器 { this( 0, 0); } void moveto(int x1, int y1) // 点移动到(x1, y1) { x = x1; y = y1; } }
注释 程序中适当地加入注释,会增加程序的可读 性 程序中允许加空白的地方就可以写注释。注 释不影响程序的执行结果,编译器将忽略注 释 Java中的三种注释形式: ∥在一行的注释 行或多行的注释 /*文档注释
注释 ▪ 程序中适当地加入注释,会增加程序的可读 性 ▪ 程序中允许加空白的地方就可以写注释。注 释不影响程序的执行结果,编译器将忽略注 释 ▪ Java中的三种注释形式: // 在一行的注释 /* 一行或多行的注释 */ /** 文档注释 */
语句、分号和块 int x=0 nt y= int z=2 System. out. print(“z只能在该内部语句块里使用! System. out. print(“x和y均可在这里使用!
语句、分号和块 ▪ Java中的语句是最小的执行单位 ▪ Java各语句间以分号“;”分隔。一个语句可写在 连续的若干行内 ▪ 花括号“{”和“}”包含的一系列语句称为语句块, 简称为块 ▪ 语句块可以嵌套 ▪ 即语句块中可以含有子语句块。在词法上,块被当作 一个语句看待 int x=0; { int y=1; { int z=2; System.out.print(“z只能在该内部语句块里使用!”); } System.out.print(“x和y均可在这里使用!”); }
Java关键字 abstract boolean break byte case catch char class const continue do double else extends false finally cast default final finally float for future generIc goto if Implements import Inner instanceof int interface long native new null operator outer package private protected public rest return short static super switch synchronized this throw throws transient true var void volatile While
Java关键字 abstract boolean break byte case catch char class const continue do double else extends false finally cast default final finally float for future generic goto if implements import inner instanceof int interface long native new null operator outer package private protected public rest return short static super switch synchronized this throw throws transient true try var void volatile while