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

1 Answer

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

3.1k questions

2.6k answers


2.7k users