Computer Applications
Write a program to input 10 alphabets in an array. Now ask the user to input an alphabet and search if the alphabet is present in the array or not using linear search technique. If found display "Search Successful" and print the index of the alphabet in the array, otherwise display "Search Unsuccessful".
Java
Java Arrays
7 Likes
Answer
import java.util.Scanner;
public class KboatLinearSearch
{
public static void main(String args[]) {
Scanner in = new Scanner(System.in);
char arr[] = new char[10];
System.out.println("Enter 10 alphabets:");
for (int i = 0; i < 10; i++) {
arr[i] = in.next().charAt(0);
}
System.out.print("Enter alphabet to search: ");
char ch = in.next().charAt(0);
int i = 0;
for (i = 0; i < 10; i++) {
if (arr[i] == ch) {
break;
}
}
if (i == 10) {
System.out.println("Search Unsuccessful");
}
else {
System.out.println("Search Successful");
System.out.println(ch + " present at index " + i);
}
}
}Output

Answered By
4 Likes
Related Questions
The statement used to find the total number of Strings present in the string array String s[] is:
- s.length
- s.length()
- length(s)
- len(s)
Define a class pin code and store the given pin codes in a single dimensional array. Sort these pin codes in ascending order using the Selection Sort technique only. Display the sorted array.
110061, 110001, 110029, 110023, 110055, 110006, 110019, 110033
What is the output of the Java code given below?
String color[] = {"Blue", "Red", "Violet"}; System.out.println(color[2].length());- 6
- 5
- 3
- 2