promotion image of download ymail app
Promoted

Can you answer my Java question plz?

write a method that takes a sorted integer array, sorted, and an integer, k, and returns the index of where the integer is located or -1 if the integer is not in the array.

3 Answers

Relevance
  • 2 months ago
    Favorite Answer

    Hi, Don. With a sorted array, you can perform a sequential search (easy to implement but relatively slow), or if the size of the array is large, a binary search is more efficient. Googling "Java binary search" should come up with the code you're after.

    • Commenter avatarLogin to reply the answers
  • Snezzy
    Lv 7
    2 months ago

    Because the array is sorted an appropriate algorithm is obvious. If it is not obvious to you, read your textbook or your class notes. 

    If you fell asleep in class the day they covered searching and sorting, then get Volume 3 of Donald Knuth's book, "The Art of Computer Programming." Drop the class and read the book instead. Do ALL the exercises.

    • Commenter avatarLogin to reply the answers
  • keerok
    Lv 7
    2 months ago

    You're not asking a question. You're asking us to do your homework for you. Not cool.

    • Don1 month agoReport

      makes sense why only 12% of your answers are favorited

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.