九九乘法表:利用反射机制获取实例
public class ChenFaBiaoDemo2 {
/**
* <p>九九乘法表</p>
* @throws IllegalAccessException
* @throws InstantiationException
* <p>利用反射机制获取实例</p>
* @created on 2012-4-24
*/
public static void main(String[] args) throws InstantiationException, IllegalAccessException {
Class clazz=ChenFaBiao2.class;
ChenFaBiao2 chenFaBiao2=(ChenFaBiao2) clazz.newInstance();
chenFaBiao2.print();
}
}
class ChenFaBiao2 {
public ChenFaBiao2(){};
public void print() {
System.out.println("中学生读九九乘法表:");
for (int i = 1; i < 10; i++) {
for (int j = 1; j < 10; j++) {
if (j <= i) {
if (i == j) {
System.out.println(i + "*" + j + "=" + i * j);
continue;
} else {
System.out.print(i + "*" + j + "=" + i * j + " ");
}
}
}
}
}
}
posted on 2012-05-10 17:58 Alfred__Lee 阅读(172) 评论(0) 收藏 举报
浙公网安备 33010602011771号