Advertisement
Carlettos

buscar suma de 2 numeros en un array

Dec 3rd, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.77 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Campus {
  4.  
  5.     static int[] a;
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner in = new Scanner(System.in);
  9.         int valor;
  10.  
  11.         System.out.println("escribe 5 elementos");
  12.         a = new int[5];
  13.  
  14.         for (int i = 0; i < a.length; i++) {
  15.             a[i] = in.nextInt();
  16.         }
  17.  
  18.         System.out.println("ingrese valor resultado de suma");
  19.         valor = in.nextInt();
  20.  
  21.         for (int i = 0; i < a.length; i++) {
  22.             for (int j = 0; j < a.length; j++) {
  23.                 if (i != j && a[i] + a[j] == valor) {
  24.                     System.out.println("Se encontrĂ³: " + a[i] + " y " + a[j]);
  25.                     System.exit(0);
  26.                 }
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement