1 package cn.lyh; 2 3 public class L { 4 5 public static void main(String[] args) { 6 int []arr = new int[30]; 7 arr[0]=1; 8 arr[1]=1; 9 for(int i=2;i<arr.length;i++) 10 arr[i]=arr[i-1]+arr[i-2]; 11 for(int i:arr) 12 System.out.print(i+" 、"); 13 14 } 15 16 }
package cn.lyh; public class L { public static void main(String[] args) { liker ker[]=new liker[3]; ker[0]=new liker("Mr、L",11); ker[1]=new liker("Mr、Y",17); ker[2]=new liker("Mr、H",19); for(int i=0;i<ker.length;i++) ker[i].getInfo(); } } class liker { private String name; private int age; public liker(String name,int age){ this.name=name; this.age=age; } public void getInfo() { System.out.println("姓名:" + this.name + " 年龄:" + this.age); } }
package cn.lyh; public class L { public static void main(String[] args) { int array[]= {0,8,4,6,2,5,3,7,9,1}; for(int i=0;i<array.length;i++) for(int j=0;j<array.length-i-1;j++) { if(array[j]>array[j+1]) { int temp =array[j]; array[j]=array[j+1]; array[j+1]=temp; } } for( int i:array) System.out.print(i+" "); } }
package cn.lyh; public class L { public static void main(String[] args) { int array[]= {0,8,4,6,2,5,3,7,9,1}; //选择排序法 for(int i=0;i<array.length;i++) for(int j=i+1;j<array.length;j++) { if(array[j]>array[i]) { int temp =array[j]; array[j]=array[i]; array[i]=temp; } } for( int i:array) System.out.print(i+" "); } }