1. 程式人生 > >Java 2017.11.20 楊浩寧作業

Java 2017.11.20 楊浩寧作業

i++ demo src images 分享 pan get () 人類

package top.hyself;
//斐波那契數列
public class Demo {

    public static void main(String[] args) {
        int[] arr = new int [30];
        arr[0] = 1;
        arr[1] = 1;
        for(int i = 2;i < arr.length;i++)
            arr[i] = arr[i - 1] + arr[i - 2];
        for(int i : arr)
            System.out.println(i);
    }

}
技術分享圖片

package top.hyself;
//人類對象數組
public class Demo {

    public static void main(String[] args) {
        human hm[] = new human[3];
        hm[0] = new human("小明",19);
        hm[1] = new human("小紅",18);
        hm[2] = new human("小誌",20);
        for(int i = 0;i < hm.length;i++)
            hm[i].getInfo();
    }

}

class human{ private String name; private int age; public human(String name,int age) { this.name = name; this.age = age; } public void getInfo() { System.out.println("姓名:" + this.name + " 年齡:" + this.age); } }
技術分享圖片

Java 2017.11.20 楊浩寧作業