開發與維運

java日常練手(面試)小示例

在這裡整理一些日常用來練手或者面試時的小示例

1. 利用 StringBuffer 或者 StringBuilder 的reverse 實現 字符串反轉
實現代碼
 public static String stringReverse(String string) {
        return new StringBuffer(string).reverse().toString();
    }
2. 打印一個九九乘法表
public static void multiplication() {
        for (int i = 1; i <= 9; i++) {
            for (int j = 1; j <= i; j++) {
                System.out.print(i + " x " + j + " = " + i * j +"   ");
            }
            System.out.println();
        }
    }
3. 題目:有一對兔子,從出生後第3個月起每個月都生一對兔子,小兔子長到第三個月後每個月又生一對兔子,假如兔子都不死,問每個月的兔子總數為多少?

Leave a Reply

Your email address will not be published. Required fields are marked *