Determining the linear search algorithm

Assignment Help Basic Computer Science
Reference no: EM131803736

Linear Search algorithm. Your program will ask the user to input 10 letters (e.g., e, c, z, x, k, m, o, a, d, f). The program will store these 10 letters into an array. Then the program will ask the user which letter the user wants to search for. If the letter is in the array, the program should return the position of the letter in the array. If the letter is NOT in the array, the message "Letter not found" should display. The user must press "E" to exit. and lastly its has to be a GUI.

import javax.swing.JOptionPane;

public class LetterSearchGUI {

 public static int search(String[] arr, String key) {

  int size = arr.length;

  for (int i = 0; i < size; i++) {

   if (key.equalsIgnoreCase(arr[i])) {

    return i;

   }

  }

  return -1;

 }

 public static void main(String a[]) {

  do {

   String[] input = new String[10];

   for (int i = 0; i < 10; i++) {

    input[i] = JOptionPane.showInputDialog("Enter the letter "

      + (i + 1) + ": ");

   }

   String searchKey = JOptionPane

     .showInputDialog("Enter the letter the user wants to search for: ");

   int pos = search(input, searchKey);

   if (pos == -1) {

    JOptionPane.showMessageDialog(null, "Letter not found");

   } else {

    JOptionPane.showMessageDialog(null, "Key " + searchKey

      + " found at index: " + pos);

   }

 

   // string for exit button

   String s = JOptionPane

     .showInputDialog("Press E to exit the program or anything to continue: ");

   if ("E".equalsIgnoreCase(s)) {

    break;

   }

  } while (true);

 }

}

Reference no: EM131803736

Questions Cloud

What are the brief facts of case that led to investigation : What are the brief facts of the case that led to the investigation
Discuss the value of simulation training-development : Discuss the value of simulation training/development. How do we as HRM professionals objectively determine the "value" of simulation training?
Describe categories of consumer decision-making behavior : Describe the three categories of consumer decision-making behavior. Name typical products for which each type of consumer behavior is used.
Which staffing strategy would you choosen : Imagine a European MNC having to staff one of its subsidiaries that acts as a regional HQ for the Asian market.
Determining the linear search algorithm : Linear Search algorithm. Your program will ask the user to input 10 letters (e.g., e, c, z, x, k, m, o, a, d, f).
What challenges are faced by corporations : What challenges are faced by corporations in reducing the barriers to a healthy diet faced by those consumers of lower SES?
Prepare a review of the article and include the abstract : prepare a review of the article, and include abstract from journal article. Your review should be succinctly written in a descriptive and informative manner.
Prepare a schedule of variable : Prepare a schedule of variable, fixed, and total manufacturing costs for each account category
Who are the typical system stakeholders : Who are the typical system stakeholders (the key players), and what are their unique roles?

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Find the posterior odds ratio

For each of the combinations in the previous exercise, find the posterior odds ratio.

  Write a program to calculate the trajectory of a cannon ball

Write a program to calculate the trajectory of a cannon ball (we use a watermelon). The program must ask the user for the initial velocity and initial trajectory angle then ask the user what they want to calculate

  Draw the simple house elevation

Draw the simple house elevation shown in Fig. 11-10 at any size with ortho or object snap tracking and polar tracking. Prior to drawing the roof, use UNDO to mark the current location in the drawing. Then draw the roof.

  Compute a compass sense of direction in such a network

Consider a synchronous square mesh with n nodes and without any sense of direction but with a designated leader. (a) Show how to compute a compass sense of direction in such a network.

  Executive capital budgeting committee

You intend to submit the project to the executive capital budgeting committee. Should the $25,000 fee be counted as part of the project costs?

  What is rule of thumb as to when a system should be replaced

All systems eventually grow old and become obsolete. What is the rule of thumb as to when a system should be replaced?

  What is the disease model of drug use

What is the disease model of drug use? Do you think that drug abuse should be viewed in this way? Why or why not?

  Research a writing guide for forensics organization

Your manager has asked you to research and recommend a writing guide that examiners in your computer forensics organization will use for all official written reports.

  Do you expect skew to be significant

Suppose we execute the word-count Map Reduce program described in this section on a large repository such as a copy of the Web. We shall use 100 Map tasks and some number of Reduce tasks.

  Security components in sdlc

Which one of the following subgroups recommended that IT centers and software assurance groups that are outside mainstream academia.

  Who is holding return real time big data analysis

Who is holding return realtime bigg data analyssis? what is the future of data big?

  Government should not prevent discrimination

Are there circumstances where the government should not prevent discrimination? Would you favor keeping discrimination?

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd