Created
May 20, 2015 21:56
-
-
Save rafaelcs/867e0bd56392c43f77a1 to your computer and use it in GitHub Desktop.
Desafio Array
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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