发布网友 发布时间:2天前
共1个回答
热心网友 时间:2天前
import java.util.Scanner;
public class test{
public static void main(String[] args) {
int x[]={-6,-5,3,88,123};
try {
System.out.print("请输入欲搜寻的资料:");
int num = new Scanner(System.in).nextInt();
if (num==-9999) {
System.out.println("程序结束!");
}else{
for (int i = 0; i < x.length; i++) {
if (x[i]==num) {
System.out.println("您搜寻的资料是第 "+(i+1)+" 笔");
break;
}else if(i==x.length - 1 && x[i]!=num){
System.out.println("找不到资料!");
}
}
}
} catch (Exception e) {
System.out.println("输入错误,程序结束!");
}
}
}