摘要:
写两个线程,一个线程打印1~52,另一个线程打印字母A-Z。打印顺序为12A34B56C78D……5152Z。要求用线程间的通信。代码清单:class Printer { private int index = 1; /* 打印数字*/ public synchronized void print(int i) { while (index % 3 == 0) { try { wait(); } catch (Exception e) { } } ... 阅读全文
摘要:
概念:最大公约数:两个整数共有因子中最大的一个方法一:如果两个数相等,则最大公约数为它本身,两个数不等,则用两个数依次除两个数中最小的一个到1,直到找到同时能被两个数除尽的那个数代码清单: public static int gcd1(int x, int y) { int result = 0; // 最大公约数 int min = x > y ? y : x; // 两个整数中最小的数 if (x == y) { result = x; } else { for (int i =... 阅读全文