package cn.wzx.www; //1 1 2 3 5 8 13 public class Fibonacci { public static void main(String[] args) { // TODO 自动生成的方法存根 int i; int[] arr = new int[30]; arr[0] = 1; arr[1] = 1; System.out.println(arr[0]); System.out.println(arr[1]); for (i = 2; i < arr.length; i++) { arr[i] = arr[i - 1] + arr[i - 2]; System.out.println(arr[i]); } } }
选择排序法
package cn.wzx.www; public class Select { public static void main(String[] args) { // TODO 自动生成的方法存根 int i, j, temp; int arr[] = { 100, 45, 39, 68, 99, 345, 436, 999, 234, 278 }; for (i = 0; i < arr.length - 1; i++) { for (j = i + 1; j < arr.length; j++) { if (arr[i] > arr[j]) { temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } } } for (i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } }
冒泡排序法
package cn.wzx.www; public class Maopao { public static void main(String[] args) { // TODO 自动生成的方法存根 int i, j, temp=0; int arr[] = { 100, 45, 39, 68, 99, 345, 436, 999, 234, 278 }; for(i=0;i<arr.length;i++){ for(j=0;j<arr.length-1;j++){ if(arr[j]>arr[j+1]){ temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } } } for (i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } }
package cn.wzx.www; public class PersonArr { public static void main(String[] args) { // TODO 自动生成的方法存根 person per[]=new person[3]; per[0]=new person ("张三",20); per[1]=new person ("李四",30); per[2]=new person ("王五",40); for(int i=0;i<per.length;i++){ per[i].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); } } /* package cn.wzx.www; public class PersonArr { public static void main(String args[]) { person per[]=new person[3]; per[0]=new person("张三",20); per[1]=new person("李四",22); per[2]=new person("王五",23); 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); } } */