1.
package com.Hani;
public class XuanZe {
//选择法
public static void main(String[] args){
int[] arr={22,43,26,7,37,66,237,64};
for(int i=0;i<arr.length;i++){
for(int j=i+1;j<arr.length;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]);
}
}
}
2.
package com.Hani;
public class MaoPao {
//冒泡法
public static void main(String[] args){
int[] arr={22,43,26,7,37,66,237,64};
for(int i=0;i<10;i++){
for(int j=0;j<arr.length-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]);
}
}
}
3、
package com.Hani;
public class Fibonacci {
//斐波纳契额数列
//1 1 2 3 5 8 13 21 34 55 89 144 233 377
public static void main(String[] args) {
int[] arr=new int[30];
arr[0]=1;
arr[1]=1;
System.out.println(arr[0]);
System.out.println(arr[1]);
for(int i=2;i<arr.length;i++){
arr[i]=arr[i-1]+arr[i-2];
System.out.println(arr[i]);
}
}
}
4、 人类对象数组
package com.Hani;
public class PersonArray {
public static void main(String args[]){
person per[]=new person[3];
per[0]=new person("鹿晗",27);
per[1]=new person("小鹿",7);
per[2]=new person("小小鹿",2);
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+"岁");
}
}