Created
June 23, 2020 11:49
-
-
Save GeorgePaiva/dbfaf60aa811e4308c052976f1e5eef9 to your computer and use it in GitHub Desktop.
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 desafiometa; | |
import java.util.*; | |
public class Questao01 { | |
public static void main(String[] args) { | |
Alvo(); | |
} | |
private static void Alvo() { | |
ArrayList<Integer> listaTemp = new ArrayList<Integer>(); | |
ArrayList<Integer> resultado = new ArrayList<Integer>(); | |
System.out.print("Alvo: "); | |
var target = Integer.parseInt(new Scanner(System.in).nextLine()); | |
ArrayList<Integer> nums = new ArrayList<Integer>(); | |
System.out.println("Digite o tamanho do array: "); | |
var total = Integer.parseInt(new Scanner(System.in).nextLine()); | |
System.out.println("Digite os números: "); | |
for (int i = 0; i < total; i++) { | |
var numero = Integer.parseInt(new Scanner(System.in).nextLine()); | |
listaTemp.add(numero); | |
} | |
Collections.sort(listaTemp); | |
for (int i = 0; i < listaTemp.size(); i++) { | |
if (listaTemp.get(i) + listaTemp.get(i + 1) == target) { | |
resultado.add(i); | |
resultado.add(i + 1); | |
System.out.print(String.format("[%1$s,%2$s]", i, i + 1)); | |
break; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment