Computer Science, asked by sayanmandal271, 1 month ago

Write a program to accept 10 different names in an array and search for a given name using linear search technique.​

Answers

Answered by bakrihullisantosh
2

import java.util.Scanner;

public class KboatSDANames

{

public static void main(String args[]) {

Scanner in = new Scanner(System.in);

String names[] = new String[10];

System.out.println("Enter 10 names");

for (int i = 0; i < names.length; i++) {

names[i] = in.nextLine();

}

System.out.print("Enter a letter: ");

char ch = in.next().charAt(0);

ch = Character.toUpperCase(ch);

for (int i = 0; i < names.length; i++) {

if (Character.toUpperCase(names[i].charAt(0)) == ch) {

System.out.println(names[i]);

}

}

}

}

Similar questions