DSA Assignment - 6
DSA Assignment - 6
if (arr[i] == target) {
return i;
return -1;
if (arr[mid] == target) {
return mid;
}
if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
return -1;
Arrays.sort(numbers);
}
2Q.Write a program that takes the details of
a person (name, age, and city) and search
for a specific name using linear search
import java.util.Scanner;
class Person {
String name;
int age;
String city;
this.name = name;
this.age = age;
this.city = city;
if (people[i].name.equalsIgnoreCase(targetName))
{
return i;
}
return -1;
int n = scanner.nextInt();
scanner.nextLine();
System.out.print("Name: ");
System.out.print("Age: ");
scanner.nextLine();
System.out.print("City: ");
if (index != -1) {
} else {
scanner.close();
if (arr[mid] == target) {
return mid;
}
if (arr[mid] < target) {
left = mid + 1;
} else {
right = mid - 1;
return -1;
int[] numbers = {12, 33, 42, 51, 66, 73, 87, 99,
101};
if (result != -1) {
} else {