Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.80 KB | None | 0 0
  1. public static void main(String[] args) {
  2.         int i, x, n,c, s;
  3.         float m;
  4.         c = 0;
  5.         s = 0;
  6.         do
  7.             n = Integer.parseInt(JOptionPane.showInputDialog("Insira a quantidade de números a calcular"));
  8.         while (n < 0);
  9.         for (i = 0; i < n; i++){
  10.             x = Integer.parseInt(JOptionPane.showInputDialog("Insira um número"));
  11.             if(x % 2 == 0){
  12.                 c++;
  13.                 s = s + x;
  14.             }
  15.         }
  16.         if (c != 0){
  17.             m = ((float) s / c);
  18.             JOptionPane.showMessageDialog(null, "Média dos números pares: "+ m +"\nPercentagem de números pares: "+ (int)((float) c / n * 100) +"%");
  19.         }else{
  20.             JOptionPane.showMessageDialog(null, "Não foram inseridos números pares");
  21.         }
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement