顺序排序(输入一个数有输出下标,没有输出不存在)
public static void main(String args[]){
int a[]={1,5,6,9,8};
Scanner scan = new Scanner(System.in);
int b = scan.nextInt();
int i = 0;
for(;i<a.length;i++){
if(b == a[i]){
System.out.println("第"+i+"位");
break;
}
}
if(i == a.length){
System.out.println("不存在");
}
}
Disclaimer: The above articles are added by users themselves and are only for typing and communication purposes. They do not represent the views of this website, and this website does not assume any legal responsibility. This statement is hereby made! If there is any infringement of your rights, please contact us promptly to delete it.