0 like 0 dislike
62 views
in Computer Science by (1.0m points)
How is the largest value from an array searched?

1 Answer

0 like 0 dislike
by (1.0m 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: School, College, University, Academy Free Homework Help

19.4k questions

18.3k answers

8.7k comments

3.2k users

Free Hit Counters
...