Advertisement
JoseLargo

Untitled

Dec 6th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.57 KB | None | 0 0
  1. package ejercicio2;
  2.  
  3. import java.util.Scanner;
  4. public class Ejercicio2 {
  5.    
  6.     public static void main(String[] args) {
  7.         Scanner sc= new Scanner(System.in);
  8.         int [] vector1;
  9.         int [] vector2;
  10.         int cont, tam1, tam2;
  11.         cont=0;
  12.        
  13.         System.out.println("¿De que tamaño quieres que sea el primer vector?");
  14.         tam1=sc.nextInt();
  15.         vector1= new int[tam1];
  16.         System.out.println("¿De que tamaño quieres que sea el segundo vector?");
  17.         tam2=sc.nextInt();
  18.         vector2= new int[tam2];
  19.        
  20.         for (int i = 0; i < vector1.length ; i++) {
  21.             System.out.println("Introduzca dato en la posicion "+i+" del primer vector: ");
  22.             vector1[i]=sc.nextInt();
  23.         }
  24.        
  25.         for (int j = 0; j < vector2.length ; j++) {
  26.             System.out.println("Introduzca dato en la posicion "+j+" del segundo vector: ");
  27.             vector2[j]=sc.nextInt();
  28.         }
  29.        
  30.         if (vector1.length==vector2.length) {
  31.             for (int i = 0; i < vector1.length ; i++) {
  32.                 if(vector1[i]==vector2[i]){
  33.                     cont++;
  34.                 }        
  35.             }
  36.              if(cont==vector1.length){
  37.                  System.out.println("Son iguales ambos arrays, en cuanto a tamaño y contenido");
  38.              }else{
  39.                  System.out.println("No son iguales los arrays, en cuanto a contenido");
  40.             }  
  41.         }else{
  42.             System.out.println("No son iguales los vectores, en cuanto a tamaño ni contenido");
  43.         }
  44.     }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement