whiplk

Média aritmética de repetidos.

Mar 7th, 2014
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.57 KB | None | 0 0
  1. package teste;
  2.  
  3. import java.util.Scanner;
  4.  
  5. public class outro {
  6.     public static void main(String[] args) {
  7.         Scanner input = new Scanner(System.in);
  8.        
  9.         int[] vetor = new int[10];
  10.        
  11.         for (int i = 0; i < 10; vetor[i++] = input.nextInt()) {}
  12.        
  13.         input.close();
  14.        
  15.         int repetidos = 0;
  16.         int r = 0;
  17.        
  18.         for (int i = 0; i < vetor.length; i++) {
  19.             for (int j = i+1; j < vetor.length; j++) {
  20.                 if (vetor[i] == vetor[j]) {
  21.                     repetidos++;
  22.                     r += vetor[i];
  23.                 }
  24.             }
  25.         }
  26.        
  27.         r /= repetidos;
  28.        
  29.         System.out.print("resultado aritmético: " + r);
  30.     }
  31. }
Advertisement
Add Comment
Please, Sign In to add comment