12
package cn.ch.w; public class A { public void getFibonacci(int number){ int nLeft = 0; int nRight = 1; System.out.print(nRight); for (int i = 0; i < number; i++) { int sum = nLeft + nRight; System.out.print(" " + sum); nLeft = nRight; nRight = sum; } } public static void main(String[] args) { new A().getFibonacci(10); } }
选择法
package cn.ch.w; public class A { public static void main(String[] args) { int[] arr={23,234,3,1,19,21,231,88,90,11}; for(int i=0;i<arr.length-1;i++) { for(int j=i+1;j<10;j++) { if(arr[i]>arr[j]) { int temp; temp=arr[i]; arr[i]=arr[j]; arr[j]=temp; } } } for(int i=0;i<arr.length;i++){ System.out.println(arr[i]); } } }
冒泡
package cn.ch.w; public class A { public static int main(String[] args) { int[] arr={23,234,3,1,19,21,231,88,90,11}; for(int i=0;i<10;i++) { for(int j=0;j<10-1-i;j++) { if(arr[j]>arr[j+1]) { int temp; temp=arr[j]; arr[j]=arr[j+1]; arr[j+1]=temp; } } } for(int i=0;i<arr.length;i++){ System.out.println(arr[i]); } return 0; } }