Skip to content

Instantly share code, notes, and snippets.

@rafaelcs
Created May 20, 2015 21:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rafaelcs/867e0bd56392c43f77a1 to your computer and use it in GitHub Desktop.
Save rafaelcs/867e0bd56392c43f77a1 to your computer and use it in GitHub Desktop.
Desafio Array
package teste;
public class TesteDesafio {
public static void main(String[] args) {
int[] a = {6,8,8,7,2,9};
int elemento1 = 0, elemento2 = 0, resultado = 0;
for (int i = 0; i < a.length; i++) {
for (int j = i + 1; j < a.length; j++) {
if ((a[i] % 3 != 0) && (a[j] % 3 != 0))
continue;
if ((a[i] * a[j]) > resultado){
resultado = a[i] * a[j];
elemento1 = a[i];
elemento2 = a[j];
}
}
}
if (resultado > 0)
System.out.println("Resultado: " + resultado + "\n Elemento1: " + elemento1 + "\n Elemento2: " + elemento2);
else
System.out.println("Sem resultado");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment