Arrays Of Strings

Arrays Of Strings

 Write a method named find. The method shall take two arguments. And  array of strings and a string t, for the target. Your method shall return true if the target t appears in the array, false otherwise. (note you will have to create a new array of strings 

class Main {

public static boolean find(String[] myStringArray, String t) {

for (String element:myStringArray ) {

if (element.equals(t)) {

return true;

}

}

return false;

}

public static void main(String[] args)

{

boolean found=find(new String[] {“Car”,”Plane”,”Bike”,”Train”},”Bike”);

if (found) {

System.out.println(“String found”);

} else {

System.out.println(“String not found”);

}

}

}

Place an Order

Plagiarism Free!

Scroll to Top