Java作业十三(2017-11-20)

/*使用一位数组解决 1 1 2 3 5 8 13 数列问题 斐波纳契数列 Fibonacci*/
package cn.GM;

public class array {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		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];
			System.out.println(arr[i]);
		}

	}
}

  

/* 选择法。从小到大排列 */
package cn.GM;

public class yiwei {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] arr = { 10, 347, 657, 38, 382, 75, 76, 56, 12344, 84654 };
		/* 选择法。从小到大排列 */
		for (int i = 0; i < arr.length - 1; i++) {
			for (int j = i + 1; j < arr.length; j++) {
				if (arr[i] > arr[j]) {
					int temp = arr[i];
					arr[i] = arr[j];
					arr[j] = temp;
				}
			}

		}
		for (int i : arr)
			System.out.println(i);
	}

}

  

/*冒泡法。从小到大排列*/
package cn.GM;

public class yiwweiM {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		int[] arr = {10, 347, 657, 38, 382, 75, 76, 56, 12344, 84654};
		/*冒泡法。从小到大排列*/
        for(int i = 0;i < arr.length;i++) {
            for(int j = 0;j < arr.length - 1 -i;j++) {
                if(arr[j] > arr[j + 1]) {
                    int temp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = temp;
                }
            }

        }
        for(int i : arr)
            System.out.println(i);
 
	}

}

  

/*人类对象数组——一堆人*/
package cn.GM;

public class personarr {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//建数组
		person arr[] = new person[3];
		arr[0] = new person("赵艺",20);
		arr[1] = new person("欧阳娜娜",17);
		arr[2] = new person("房祖名",32);
        for(int x = 0;x < arr.length;x++)
        	arr[x].getInfo();
    }

}

class person{
    private String name;
    private int age;
    public person(String name,int age) {
        this.name = name;
        this.age = age;
    }
    public void getInfo() {
        System.out.println("姓名:" + this.name + " 年龄:" + this.age);

}

	

}

  

posted @ 2017-11-21 23:33  So.cool  阅读(226)  评论(0编辑  收藏  举报