Question: Write a method to search for the first occurrence of a character in a string. If you have the character in the string, you

Write a method to search for the first occurrence of a character in a string. If you have the character in

Write a method to search for the first occurrence of a character in a string. If you have the character in the string, you should return it's index otherwise throw NoSuchElementException with an appropriate string parameter. The NoSuchElementException is in java.util package. Add proper JavaDoc comments and necessary inline comments. Make sure to test your method with a few test cases.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

import javautilNoSuchElementException Searches for the first occurrence of a character in a string p... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!