Linear search algorithm

Assignment Help Basic Computer Science
Reference no: EM131802157

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: EM131802157

Questions Cloud

What was the amortization expense amount per month : Chamber Company purchased a truck on January 1 20A, at a cash cost of $10,600. What was the amortization expense amount per month
Structured analysis-design : Who are the typical system stakeholders (the key players), and what are their unique roles?
Advocates of shareholder capitalism tend : Advocates of shareholder capitalism tend to do all of the following EXCEPT:
Discuss the features of cognitive learning : List and discuss three features of cognitive learning. Write a minimum of 3 sentences about each feature.
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.
Prepare the journal entry to record the acquisition : Land $22,500, Building $58,500, and Fixtures $9,000. Prepare the journal entry to record the acquisition. Show your work
What do you think about the whole situation : What do you think about the whole situation. Develop a proper quantitative analysis
Write clearly and persuasively using proper grammar : Write clearly, coherently, and persuasively using proper grammar, mechanics, and formatting appropriate to the situation.
Describe the importance of vba : What is VBA? Why do we need VBA, in two lengthy paragraph describe the importance of VBA

Reviews

Write a Review

Basic Computer Science Questions & Answers

  Develop an entity-relationship diagram as a conceptual model

For the following data requirements analysis description, develop an Entity-Relationship Diagram as a conceptual model that captures all of the requirements to the fullest extent possible.

  Logic flow chart with four methods

Create a Visual Logic flow chart with four methods. Main method will create an arrayof 5 elements, then it will call a read method, a sort method and a print methodpassing the array to each.

  Mobile application management

Although not as widely used as MDMs, mobile application management (MAM) tools can provide a higher degree of security by securing apps on a mobile device.

  What percentage of these vineyards are under 60 acres

Write a brief description of this distribution (shape, center, spread, unusual features).

  Dynamic programming technique

Please briefly introduce the dynamic programming technique. What do you think about its efficiency? What are the hallmarks where dynamic programming could be applied?

  Test the null hypothesis that the three treatments

Test the null hypothesis that the three treatments have the same effect on bacterial concentration.

  Find the average salary of employees

You subsequently realize that updates to these relations are frequent. Because indexes incur a high overhead, can you think of a way to improve performance on these queries without using indexes?

  Is this circuit good for anything or is it a flop

Analyze the BUT flop as a feedback sequential circuit and obtain excitation equations, transition table, and flow table. Is this circuit good for anything, or is it a flop?

  Create your own cognitive biometric memorable event

The final step should be a fill-in-the-blank user response. Compare your steps with those of other learners. Which do you find the easiest for users?

  Calculate the future value of an? annuity

1) Calculate the future value of an? annuity, with case A being an ordinary annuity and case B being an annuity due.

  Jpmorgan and is hiring practices in china

What public policies are furthered by this law

  Short-distance baseband transmission and for ir signaling

Line-coding is a technique used in short-distance baseband transmission and for IR signaling. Based on the NZR (non-zero) Manchester-encoding technique, line-coding for IR signals depends on modulated light rays. Briefly describe how emitted IR li..

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