11.20
阿新 • • 發佈:2017-11-27
ima ray 之前 rgs person ring package pre 技術分享
package lzb; 2 3 public class LIUZHIBO { 4 public static void main(String[] args) { 5 int[] arr = new int [30]; 6 arr[0] = 1; 7 arr[1] = 1; 8 for(int i = 2;i < arr.length;i++) 9 arr[i] = arr[i-1] + arr[i-2]; 10 for(int i : arr) 11 System.out.println(i); 12 } 13 14 }
1 package LZB; 2 3 public class LIUZHIBO666 { 4 public static void main(String[] args) { 5 int[] arr={1,3,2,45,65,33,12}; 6 System.out.println("交換之前:"); 7 for(int num:arr){ 8 System.out.print(num+" "); 9 } 10 for( 11 int i = 0; i < arr.length - 1; i++) { 12 int k = i; 13 for(int j = k + 1; j < arr.length; j++){ 14 if(arr[j] < arr[k]){ 15 k = j; 16 } 17 } 18 if(i != k){ 19 int temp = arr[i]; 20 arr[i] = arr[k]; 21 arr[k] = temp; 22 } 23 } 24 25 System.out.println(); 26 System.out.println("交換後:"); 27 for(int num:arr){ 28 System.out.print(num+" "); 29 } 30 } 31 }
1 package LZB; 2 3 public class lzb666 { 4 public static void main(String[] args) 5 { int[] arr={12,45,23,67,56,34,99,123}; 6 System.out.println("排序前數組為:"); 7 for(int num:arr) 8 { 9 System.out.print(num+" "); 10 } 11 for(int i=0;i<arr.length-1;i++){ 12 for(int j=0;j<arr.length-1-i;j++){ 13 if(arr[j]>arr[j+1]){ 14 int temp=arr[j]; 15 arr[j]=arr[j+1]; 16 arr[j+1]=temp; 17 } 18 } 19 } 20 System.out.println(); 21 System.out.println("排序後的數組為:"); 22 for(int num:arr){ 23 System.out.print(num+" "); 24 } 25 } 26 }
1 package lzb; 2 3 public class PersonArray { 4 public static void main(String args[]) 5 { 6 person per[]=new person[3]; 7 per[0]=new person("張三",20); 8 per[1]=new person("李四",22); 9 per[2]=new person("王五",23); 10 for (int x=0;x<per.length;x++) 11 { 12 per[x].getinfo(); 13 } 14 } 15 } 16 class person 17 { 18 private String name; 19 private int age; 20 public person(String name,int age) 21 { 22 this.name=name; 23 this.age=age; 24 } 25 public void getinfo() 26 { 27 System.out.println("姓名: "+this.name+" 年齡: "+this.age); 28 } 29 }
11.20