AJBM Posted March 5, 2012 Report Share Posted March 5, 2012 Boas! Eu tenho um array e tenho que fazer um programa que de o maior elemento do array int [] lista={12, 5, -21, 10, -345, 22, 50, -125, 80,-1} podem me dar alguma dica? Link to comment Share on other sites More sharing options...
joaorosa Posted March 5, 2012 Report Share Posted March 5, 2012 Posso. Terás de iterar pela sequência e comparar valores. 😄 Link to comment Share on other sites More sharing options...
AJBM Posted March 5, 2012 Author Report Share Posted March 5, 2012 ja consegui, fica aqui o codigo int max=lista[0]; for(int i=0;i<lista.length;i++){ if(lista[i]>max){ max=lista[i]; } } System.out.println("numero maximo: "+max); Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now