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
Consider the following two-dimensional array and answer the questions given below:
int x[ ][ ] = {{4,3,2}, {7,8,2}, {8, 3,10}, {1, 2, 9}};(a) What is the order of the array?
(b) What is the value of x[0][0]+x[2][2]?
Define a class to search for a value input by the user from the list of values given below. If it is found display the message "Search successful", otherwise display the message "Search element not found" using Binary search technique.
5.6, 11.5, 20.8, 35.4, 43.1, 52.4, 66.6, 78.9, 80.0, 95.5.
A single dimensional array has 50 elements, which of the following is the correct statement to initialize the last element to 100.
- x[51]=100
- x[48]=100
- x[49]=100
- x[50]=100
Write a Java program to store n numbers in an one dimensional array. Pass this array to a function number(int a[]). Display only those numbers whose sum of digit is prime.