JAVA经典代码总结

JAVA经典代码总结

1.打印九九乘法表:

public class UseFor2 {

public static void main(String[] args){

int i=1;

for(;i<=9;i++){

int j=1;

for(;j<=i;j++){

System.out.print(i+"*"+j+"="+i*j+"\t");

}

System.out.println();

}

}

}

2.高斯算法示例

public class ForABC{

public static void main(String args[]){

int i ;

int a[] = { 11,22,33,44,55,66,77,88,99 };

for ( i = 0 ; i <= a.length / 2 ; i ++ ){

System.out.print(a[i]+a[a.length-i-1]+ " ");

System.out.println( );

}

}

}

3.多态高级题目:

public class TestNNNNNNN {

/*1.传参的时候需要注意一个原则: 就近原则:找形参的类型和自身类型最接近的那个方法

2.多态的时候,如a2能调用A类里的show(D)和show(A) ,但是 show(A)被B类重写了,所以实际调用B类里的show(A)

*/

public static void main(String[] args) {

A a1 = new A();

A a2 = new B();

B b = new B();

C c = new C();

D d = new D();

//

System.out.println(a1.show(b));

System.out.println(a1.show(c));

JAVA经典代码总结相关文档

最新文档

返回顶部