Question

In Java I am trying to search for a string in appList array and return the...

In Java I am trying to search for a string in appList array and return the app name if found, if not return null.

I have the following but get errors compiling:

/*Find an app based on its name

* @param name the name of the app to search for

* @return the app with the given name

* or null if there is no app with that name */

public App findApp(String name)

{

for (int i=0; i < appList.length; i++)

{

if(appList[i].equals(name))

{

return name;

}

else

{

return null;

} }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.*;

public class Main
{ // declaration of the array
String appList[] = {"google", "facebook", "twitter", "bounce", "rapido"};

public String AppfindApp(String name)
{
for (int i=0; i < appList.length; i++)
{
if(appList[i].equals(name))
{
return name;
}
}
return null;
}
  
   public static void main(String[] args)
   {
   Main a = new Main(); // passing argument as google
   String result = a.AppfindApp("google");
   System.out.println(result);
   }
}

OUTPUT :

google ... Program finished with exit code 0 Press ENTER to exit console.

Add a comment
Know the answer?
Add Answer to:
In Java I am trying to search for a string in appList array and return the...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • I am trying to search a name on a list and then remove it by invoking...

    I am trying to search a name on a list and then remove it by invoking the remove function. However when I search for the name it keeps on saying name not found. What am I doing wrong? (The instruction is in the comments) The remove and drop(delete) coding I have so far is below. void buddyList::remove(buddy * r) { buddy * b4 = head; if (r == head) head = head->next; else { while (b4->next != r) { b4...

  • I am currently using eclipse to write in java. A snapshot of the output would be...

    I am currently using eclipse to write in java. A snapshot of the output would be greatly appreciated to verify that the program is indeed working. Thanks in advance for both your time and effort. Here is the previous exercise code: /////////////////////////////////////////////////////Main /******************************************* * Week 5 lab - exercise 1 and exercise 2: * * ArrayList class with search algorithms * ********************************************/ import java.util.*; /** * Class to test sequential search, sorted search, and binary search algorithms * implemented in...

  • Hi, I am writing Java code and I am having a trouble working it out. The...

    Hi, I am writing Java code and I am having a trouble working it out. The instructions can be found below, and the code. Thanks. Instructions Here are the methods needed for CIS425_Student: Constructor: public CIS425_Student( String id, String name, int num_exams ) Create an int array exams[num_exams] which will hold all exam grades for a student Save num_exams for later error checking public boolean addGrade( int exam, int grade ) Save a grade in the exams[ ] array at...

  • Why is my java method returning "-1" even if the string is in the array? The...

    Why is my java method returning "-1" even if the string is in the array? The method is:        public static int findWord(String wordToFind {        boolean found=false;            int i=0;            while (i<words.length&& !found)                if (words[i]==wordToFind)                    found=true;                else i++;                if (found)                    return i;                else return -1;   ...

  • Below I have my 3 files. I am trying to make a dog array that aggerates...

    Below I have my 3 files. I am trying to make a dog array that aggerates with the human array. I want the users to be able to name the dogs and display the dog array but it isn't working. //Main File import java.util.*; import java.util.Scanner; public class Main {    public static void main(String[] args)    {    System.out.print("There are 5 humans.\n");    array();       }    public static String[] array()    {       //Let the user...

  • write a program which include a class containing an array of words (strings).The program will search...

    write a program which include a class containing an array of words (strings).The program will search the array for a specific word. if it finds the word:it will return a true value.if the array does not contain the word. it will return a false value. enhancements: make the array off words dynamic, so that the use is prompter to enter the list of words. make the word searcher for dynamic, so that a different word can be searched for each...

  • I'm trying to make a recursive binary search that checks whether or not the words in...

    I'm trying to make a recursive binary search that checks whether or not the words in a file are correct by comparing it to a dictionary file, but for some reason the method I'm using below is not working and is outputting all the words in the file I am checking as incorrect. (the dictionary is organized in alphabetical order however the file "oliver.txt" is not) my question is what do I have to do to make this work? public...

  • I am trying to make a linked list queue and I am trying to use the...

    I am trying to make a linked list queue and I am trying to use the display method I made just to see if its working but when I run it nothing is displayed please help. Also the newPlane boolean was made just so I can randomly decide if the plane is going to join the queue or not. public class PlaneSimulation { public static void main(String[] args) { int landTime = 2; int takeoffTime = 3; int avgArrivalInterval =...

  • composed the following java code to read a string from a text file but receiving compiling...

    composed the following java code to read a string from a text file but receiving compiling errors. The text file is MyNumData.txt. Included the original java script that generated the output file. Shown also in the required output results after running the java program. I can't seem to search for the string and output the results. Any assistance will be greatly appreciated. import java.io.BufferedReader; import java.io.FileReader; import java.util.ArrayList; public class Main {   public static void main(String[] args) {     System.out.print("Enter the...

  • please help with program,these are he requirements: I am also getting a "missing return statement" in...

    please help with program,these are he requirements: I am also getting a "missing return statement" in my milestone class Create a new class Milestone which contains at least an event description, a planned completion date, and an actual completion date (which will be unset when the milestone is created). There should be a method to changed the planned completion date as well as a method to designate the Milestone as achieved. Add a method that returns whether the milestone has...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT