首页 > 试题广场 >

在数组中查找键盘输入的整数。如果找到则输出该整数在数组中的序

[问答题]

在数组中查找键盘输入的整数。如果找到则输出该整数在数组中的序号,否则输出 “not found”

例如:运行程序

输入 99, 程序输出 : 99 在数组中的序号是 5

输入 59, 程序输出 :not found

【程序】

import java.util.*;

class Exam23{

public static void main(String[]args) throws IOException{

int 6 ={83,75,92,67,55,99,78,61};

Scanner sc=new Scanner(System.in));

int x=sc.nextInt();

int index=-1;

for(int i=0; 7 ;i++)

if (a[i]==x){

index=i;

break;

}

if( 8 )

System.out.println("not found");

else

System.out.println(index);

}

}


(6)a[] (7)i<a.length (8)index==-1
发表于 2017-05-15 14:00:34 回复(0)

【供选择的答案】

(6) A 、 a[8] B 、 a[]

C 、 a D 、 new a[8]

(7) A 、 a[i]!=x B 、 a[i]==x

C 、 i<=a.length D 、 i<a.length

(8) A 、 index!=-1 B 、 a[i]!=x

C 、 a[index]==x D 、 index==-1
发表于 2017-05-11 22:44:28 回复(4)