import java.util.Scanner;
class Lu {
public static void main (String[]args) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入一个数组的长度");
int i = sc.nextInt();
int [] arr = new int [i];
for (int j = 0;j< i ;j++ ) {
Scanner sc1 = new Scanner(System.in);
System.out.println("请输入数组中第"+(j+1)+"元素");
int y = sc1.nextInt();
arr [j] = y ;
}
Bian (arr);
LookFor(arr);
}
public static void Bian(int [] arr) {
System.out.print("[");
for (int x=0;x<arr.length ;x++ ) {
System.out.print(arr[x]+" ");
if (x==arr.length-1) {
System.out.print(arr[x]+"]");
}
}
}
public static void LookFor(int [] arr) {
Scanner sc2 = new Scanner(System.in);
System.out.println("请输入一个数组的中的数");
int y = sc2.nextInt();
for (int x=0;x<arr.length ;x++ ) {
if (arr[x]== y ) {
System.out.println("该数组的角标为"+x);
}
}
}
} |
|