Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and medical aesthetics - JAVA programming; Define two integer arrays a and b, and fill in the values respectively. Use the usual methods of the Arrays class to do the following:
JAVA programming; Define two integer arrays a and b, and fill in the values respectively. Use the usual methods of the Arrays class to do the following:
Import java.util.arrays;

Public class Du2 1 {

Public static void main(String[] args) {

int[] a = { 1,23,5,57, 129, 1 1 };

int[] b = {2,4,6,8, 10, 13,3 };

boolean isEqual = Arrays.equals(a,b); //Test for equality

System.out.println("a = b? +is equal);

System.out.println ("Before sorting by ASC, the array is:");

print array(a);

arrays . sort(a); //Group A is arranged in ascending order.

System.out.println ("After sorting by ASC, an array is:");

print array(a);

//Query whether there is a user-specified value in array A arranged in ascending order.

int num 1 = 1 1,num2 = 22

int index = Arrays.binarySearch(a,num 1);

int index 2 = arrays . binary search(a,num 2);

if(index & lt; 0){

System.out.println (num1+not found in array a);

} Otherwise {

System. out.println (num1+"position in array a"+index+");

}

if(index 2 & lt; 0){

System.out.println (num 2+not found in array a);

} Otherwise {

System.out.println(num2+"in the position of array A"+index+");

}

}

Private static void printArray(int[] a) {

for(int I = 0; I<a. Length; i++){

System.out.print(a[i] +",");

}

system . out . println();

}

}

-testing.

a = b? wrong

Before sorting by ASC, the array is:

1, 23, 5, 57, 129, 1 1,

After sorting by ASC, the array is:

1, 5, 1 1, 23, 57, 129,

1 1 in position 2 of array a.

22 not found in array a.