11.20


package
GJS; public class Z { 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 GJS;

public class X {
         public static void main(String[] args) { 
        int[] arr={1,3,2,45,65,33,12}; 
        System.out.println("交换前:");
        for(int num:arr){ 
        System.out.print(num+" "); 
        } 
        for(
        int i = 0; i < arr.length - 1; i++) {
        int k = i; 
        for(int j = k + 1; j < arr.length; j++){
        if(arr[j] < arr[k]){  
                 k = j; 
                    } 
                } 
        if(i != k){  
        int temp = arr[i]; 
                arr[i] = arr[k]; 
                arr[k] = temp; 
                } 
        } 

        System.out.println();
        System.out.println("交换后:"); 
        for(int num:arr){
        System.out.print(num+" "); 
        } 
        } 
        }

 

package GJS;

public class C {
    public static void main(String[] args) 
    { int[] arr={12,45,23,67,56,34,99,123}; 
    System.out.println("排序前数组为:"); 
    for(int num:arr)
    { 
    System.out.print(num+" "); 
    } 
    for(int i=0;i<arr.length-1;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; 
    } 
    } 
    } 
    System.out.println(); 
    System.out.println("排序后的数组为:"); 
    for(int num:arr){ 
    System.out.print(num+" "); 
    } 
    } 
}

 

package GJS;

public class A {
    public static void main(String args[])
    {
        person per[]=new person[3];
        per[0]=new person("ZZZ",32);
        per[1]=new person("XXX",25);
        per[2]=new person("CCC",29);
        for (int x=0;x<per.length;x++)
        {
            per[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-26 20:33  FM10086  阅读(154)  评论(0编辑  收藏  举报