Advertisement
Jurado001

TP0E1-MostrarMedia

Aug 25th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.49 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Ptov2 {
  4.  
  5.     public static void main(String[] args) {
  6.         int n,i,j,cont1=0,cont2=0;
  7.         double sum1=0,sum2=0;
  8.        
  9.         Scanner S=new Scanner(System.in);
  10.         System.out.print("Cantidad de elementos a cargar: ");
  11.         n=S.nextInt();
  12.        
  13.         int[]vec1 = new int[n];
  14.         int[]vec2 = new int[n];
  15.        
  16.         for(i=0; i<n; i++) {
  17.             System.out.print("Ingrese el elemento "+i+" del Vector 1: ");
  18.             vec1[i]=S.nextInt();
  19.         }
  20.         System.out.println();
  21.        
  22.         for(i=0; i<n; i++) {
  23.             System.out.print("Ingrese el elemento "+i+" del Vector 2: ");
  24.             vec2[i]=S.nextInt();
  25.         }
  26.         System.out.println();
  27.        
  28.         //Suma(vec1,vec2,n);
  29.         //ProductoEsc(vec1,vec2))1;
  30.        
  31.         for(j=0;j<vec1.length;j++) {
  32.             sum1+=vec1[j];
  33.             sum2+=vec2[j];
  34.         }
  35.         System.out.println("La media del vector 1 es: "+sum1/n);
  36.         System.out.println("La media del vector 2 es: "+sum2/n);
  37.         System.out.println();
  38.        
  39.         System.out.print("El/Los valor(es) del vector 1 que supera(n) su media son: ");
  40.         for (j=0; j<vec1.length;j++) {
  41.             if (vec1[j]>sum1/n) {
  42.                 System.out.print(vec1[j]+", ");
  43.                 cont1+=1;
  44.             }
  45.         }
  46.         if(cont1==0) {
  47.             System.out.println("***Ningun valor supera la media***");
  48.         }
  49.         System.out.println();
  50.        
  51.         System.out.print("El/Los valor(es) del vector 2 que supera(n) su media son: ");
  52.         for (j=0; j<vec1.length;j++) {
  53.             if (vec2[j]>sum2/n) {
  54.                 System.out.print(vec2[j]+", ");
  55.                 cont2+=1;
  56.             }
  57.         }
  58.         if(cont2==0) {
  59.             System.out.println("***Ningun valor supera la media***");
  60.         }
  61.     }
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement