/*
* 실습) 배열에서 특정값 찾기
*
*/
public class Test003 {
public static void main(String[] args) {
int[] arr = {9, 3, 5, 7, 1, 6, 8, 4, 2};
int key = 2, i;
for (i=0; i<arr.length; i++)
if (arr[i] == key)
break;
if (i<arr.length)
System.out.println("찾은 위치 : "+ i);
else
System.out.println("못찾음");
}
}
댓글 없음:
댓글 쓰기