0 like 0 dislike
3 views
asked in Computer Science by (283k points)
How is the largest value from an array searched?

1 Answer

0 like 0 dislike
answered by (283k points)
Have a max int and set it to the first value in the array. Then in a for loop iterate through the whole array and see if the max int is larger than the int at the current index.

int max = array.get(0);

for (int i = 1; i < array.length; i++) {

if (array.get(i) > max) {

max = array.get(i)
Welcome to Free Homework Help, where you can ask questions and receive answers from other members of the community. Anybody can ask a question. Anybody can answer. The best answers are voted up and rise to the top. Join them; it only takes a minute:

6.9k questions

6k answers

22 comments

3.2k users

Categories

...