작성
·
308
0
답변 3
2
1
0
질문에 코드가 읽기 불편하게 올라가서 ...
import java.util.Sacnner; public class linearSearch{ public static void main(String[] args){ int [] arr = {0};int target; System.out.println(“type elements of array”); for(int i =0; i<10; i++){ Scanner sc = new Scanner(System.in); arr[i] = (sc.nextInt()); } System.out.println("type the target element"); Scanner t = new Scanner(System.in); target = t.nextInt(); search(arr, 0, arr.length-1, target); public static int search(int [] data, int begin, int end, int target){ int middle,index; if(begin > end){ return -1; }else{ middle = (begin+end)/2; if(data[middle] == target){ return middle; } index = search(data, begin, middle-1, target); if(index != -1){ return index; }else{ return search(data, middle+1, end, target); } } } }