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

1 Answer

0 like 0 dislike
answered by (474k 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:

10.2k questions

9.2k answers

26 comments

3.2k users

Categories

Free Hit Counters
...