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

  Identifies the cost of computer

identifies the cost of computer components to configure a computer system (including all peripheral devices where needed) for use in one of the following four situations:

  Input devices

Compare how the gestures data is generated and represented for interpretation in each of the following input devices. In your comparison, consider the data formats (radio waves, electrical signal, sound, etc.), device drivers, operating systems suppo..

  Cores on computer systems

Assignment : Cores on Computer Systems:  Differentiate between multiprocessor systems and many-core systems in terms of power efficiency, cost benefit analysis, instructions processing efficiency, and packaging form factors.

  Prepare an annual budget in an excel spreadsheet

Prepare working solutions in Excel that will manage the annual budget

  Write a research paper in relation to a software design

Research paper in relation to a Software Design related topic

  Describe the forest, domain, ou, and trust configuration

Describe the forest, domain, OU, and trust configuration for Bluesky. Include a chart or diagram of the current configuration. Currently Bluesky has a single domain and default OU structure.

  Construct a truth table for the boolean expression

Construct a truth table for the Boolean expressions ABC + A'B'C' ABC + AB'C' + A'B'C' A(BC' + B'C)

  Evaluate the cost of materials

Evaluate the cost of materials

  The marie simulator

Depending on how comfortable you are with using the MARIE simulator after reading

  What is the main advantage of using master pages

What is the main advantage of using master pages. Explain the purpose and advantage of using styles.

  Describe the three fundamental models of distributed systems

Explain the two approaches to packet delivery by the network layer in Distributed Systems. Describe the three fundamental models of Distributed Systems

  Distinguish between caching and buffering

Distinguish between caching and buffering The failure model defines the ways in which failure may occur in order to provide an understanding of the effects of failure. Give one type of failure with a brief description of the failure

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