码迷,mamicode.com
首页 > 编程语言 > 详细

Java 2017.11.20 杨浩宁作业

时间:2017-11-20 21:54:48      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:img   分享图片   public   his   sel   pack   http   jpg   str   

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 杨浩宁作业

标签:img   分享图片   public   his   sel   pack   http   jpg   str   

原文地址:http://www.cnblogs.com/Hyself/p/7868016.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!