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
6 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
A single dimensional array contains 37 elements. Which of the following represents the index of its second-to-last element.
Consider the following program segment and answer the questions given below:
int x[][] = {{2,4,5,6}, {5,7,8,1}, {34, 1, 10, 9}};
(a) What is the position of 34?
(b) What is the result of x[2][3] + x[1][2]?
A class teacher wants to arrange the names of her students in alphabetical order. Define a class NameSorter that stores the given names in a one-dimensional array. Sort the names in alphabetical order using Bubble Sort technique only and display the sorted names.
Aryan, Zoya, Ishaan, Neha, Rohan, Tanya, Manav, Simran, Kabir, Pooja
public class NameSorter { void bubbleSort(String names[]) { int len = names.length; _______(1)_________ { _______(2)_________ { _______(3)_________ { String t = names[j]; _______(4)_________ _______(5)_________ } } } } public static void main(String[] args) { String arr[] = {"Aryan", "Zoya", "Ishaan", "Neha", "Rohan", "Tanya", "Manav", "Simran", "Kabir", "Pooja" }; NameSorter obj = new NameSorter(); obj.bubbleSort(arr); for (int i = 0; i < arr.length; i++) { System.out.println(arr[i]); } } }
Name the below structure:
- One dimensional array
- Two Dimensional array with 4 rows and 5 columns
- Three dimensional array
- Two Dimensional array with 5 rows and 4 columns