package find;
import java.util.Scanner;
public class SequelSearch {
public static void main(String[] args) {
int [] A = new int[20];
for(int i=0;i<A.length;i++)
{
A[i] = (int)(Math.random()*100) + 1;
System.out.print(A[i] + ",");
}
// int[] A = new int[] { 22, 78, 63, 27, 31, 9, 36, 24, 11,33 };
// for(int i=0;i<A.length;i++)
// {
// System.out.print(A[i] + ",");
// }
System.out.println();
System.out.print("要查找的数字: ");
Scanner sc = new Scanner(System.in);
int key = sc.nextInt();
if (search(A, key) == true) {
System.out.println("恭喜你,已为你查找到数字: " + key);
} else {
System.out.println("很遗憾,没有你要查找的数字: " + key);
}
}
public static boolean search(int[] a, int s) {
boolean flag = false;
for (int i = 0; i <= a.length - 1; i++) {
if (s == a[i]) {
flag = true;
System.out.println("是第"+(++i)+"个数");
}
}
return flag;
}
}
import java.util.Scanner;
public class SequelSearch {
public static void main(String[] args) {
int [] A = new int[20];
for(int i=0;i<A.length;i++)
{
A[i] = (int)(Math.random()*100) + 1;
System.out.print(A[i] + ",");
}
// int[] A = new int[] { 22, 78, 63, 27, 31, 9, 36, 24, 11,33 };
// for(int i=0;i<A.length;i++)
// {
// System.out.print(A[i] + ",");
// }
System.out.println();
System.out.print("要查找的数字: ");
Scanner sc = new Scanner(System.in);
int key = sc.nextInt();
if (search(A, key) == true) {
System.out.println("恭喜你,已为你查找到数字: " + key);
} else {
System.out.println("很遗憾,没有你要查找的数字: " + key);
}
}
public static boolean search(int[] a, int s) {
boolean flag = false;
for (int i = 0; i <= a.length - 1; i++) {
if (s == a[i]) {
flag = true;
System.out.println("是第"+(++i)+"个数");
}
}
return flag;
}
}