1 public class exp2 {
2 /**
3 * 题目:古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,
4 * 小兔子长到第四个月后每个月又生一对兔子,
5 * 假如兔子都不死,问每个月的兔子总数为多少?
6 * @param args
7 */
8
9 public static void main(String args[]) {
10 int i = 0;
11
12 for (i = 1; i <= 20; i++)
13 System.out.println(f(i));
14 }
15
16 public static int f(int x) {
17
18 if (x == 1 || x == 2)
19 return 1;
20 else
21 return f(x - 1) + f(x - 2);
22 }
23 }
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
/**
* @author 刘学 2014-7-22 下午3:40:12
* @邮箱 375565049@qq.com
*/
public class exp3 {
/**求s=a+aa+aaa+aaaa+aa...a的值,
* 其中a是一个数字。例如2+22+222+2222+22222(此时共有5个数相加),几个数相加有键盘控制。
* @param args
* @throws IOException
*/
public static void main(String[] args) throws IOException {
// TODO Auto-generated method stub
int i, j = 0;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("input a number:");
i = Integer.parseInt(br.readLine());
System.out.println("your number is " + i);
for (int m=i; m>0; m--)
for (int x = 0; x < m; x++) {
j += i * Math.pow(10, x);
}
System.out.println("after count is " + j);
}
}
1 /**
2 * @author 刘学 2014-7-22 下午4:17:04
3 * @邮箱 375565049@qq.com
4 */
5 public class exp4 {
6
7 /**
8 * 题目:一球从100米高度自由落下,每次落地后反跳回原高度的一半; 再落下,求它在 第10次落地时,共经过多少米?第10次反弹多高?
9 *
10 * @param args
11 */
12 public static void main(String[] args) {
13 // TODO Auto-generated method stub
14
15 double high = 100.00d, highCount = 0d;
16 for (int i = 1; i <= 10; i++)
17 highCount += countHigh(high, i);
18 System.out.println("共经过" + highCount + "米!");
19 System.out.println("第十次弹起" + countHigh(high, 10) + "米!");
20 }
21
22 public static double countHigh(double high, int times) {
23
24 if (times == 1) {
25 return 100;
26 }
27 return countHigh(high, times - 1) / 2;
28
29 }
30
31 }
1 /**
2 * @author 刘学 2014-7-22 下午4:17:04
3 * @邮箱 375565049@qq.com
4 */
5 public class exp5 {
6
7 /**题目:有1、2、3、4个数字,能组成多少个互不相同且无重复数字的三位数?都是多少?
8
9 1.程序分析:可填在百位、十位、个位的数字都是1、2、3、4。组成所有的排列后再去 掉不满足条件的排列。
10 * @param args
11 */
12 public static void main(String[] args) {
13 // TODO Auto-generated method stub
14 int count = 0;
15 for (int i = 1; i <= 4; i++)
16 for (int j = 1; j <= 4; j++)
17 for (int k = 1; k <= 4; k++)
18 if (i != j && i != k && j != k) {
19 int result = 0;
20 result = (int) (i * Math.pow(10, 0) + j
21 * Math.pow(10, 1) + k * Math.pow(10, 2));
22 count++;
23 System.out.println("第" + count + "个這樣的數是" + result);
24 }
25 System.out.println("这样的数字共有" + count + "个。");
26 }
27 }
1 /**
2 * @author 刘学 2014-7-22 下午4:17:04
3 * @邮箱 375565049@qq.com
4 */
5 public class exp6 {
6
7 /**题目:一个整数,它加上100后是一个完全平方数,‘
8 * 再加上168又是一个完全平方数,请问该数是多少?
9 * 程序分析:在10万以内判断,先将该数加上100后再开方,再将该数加上268后再开方,
10 * 如果开方后的结果满足如下条件,即是结果。请看具体分析:
11 * @param args
12 */
13 public static void main(String[] args) {
14 // TODO Auto-generated method stub
15 for (int i = 0; i < 1000; i++) {
16 for (int j = 0; j < 1000; j++) {
17 for (int j2 = 0; j2 < 1000; j2++) {
18 if((j+100 == i*i) && (j+268 == j2*j2)){
19 System.out.println(j+"--"+i+"--"+j2);
20 }
21 }
22 }
23 }
24
25 }
26 }