bbsort
public class 十六 {public int bubbleSort(int[] num) {
for (int i = 0; i < num.length; i++) {
boolean swapFlag = false;
for (int j = 0; j < num.length - i - 1; j++) {
if (num[j] > num[j + 1]) {
int tmp = num[j];
num[j] = num[j + 1];
num[j + 1] = tmp;
swapFlag = true;
}
}
if (!swapFlag) {
System.out.println("right");
break;
}
}
return -1;
}
public static void main(String[] args)
{
十六 homeWork=new 十六();
int[] num1={2,3,3,2,1};
int[] num2={12,3,3,12,2};
System.out.println(homeWork.bubbleSort(num1));}}
binarySreach
public class 十六 {ublic int binarySearch(int[] num,int toFind){
return binarySearchInternal(num,toFind,0,num.length-1);
}
public int binarySearchInternal(int[] num,int toFind,int left,int right)
{
if (left>right){
return -1;
}
int mid=(left+right)>>1;
if (num[mid]==toFind)return mid;
else if (toFind<num[mid]){
return binarySearchInternal(num, toFind, left, mid-1);
}else {
return binarySearchInternal(num, toFind, mid+1, right);
}
}
public static void main(String[] args)
{
十六 homeWork=new 十六();
int[] num1={2,3,3,2,1};
int[] num2={12,3,3,12,2};
System.out.println(homeWork.binarySearchInternal(num1,3,1,3));}}
pack
`class Car{
String engine;
String lunzi;
String fangxiangpan;
String anjian;
}
public class 十十八
{
public static void main(String[] args)
{
Car car=new Car();
car.anjian="di";
car.engine="fire";
car.fangxiangpan="roll";
car.lunzi="go";
}
}
`