Advertisement
leonflicts

6 Classifica os elementos do vetor

Dec 7th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.18 KB | None | 0 0
  1. //CLASSE
  2.  
  3. package classificanumeros;
  4.  
  5. import javax.swing.JOptionPane;
  6.  
  7. public class Classifica {
  8.  
  9.     int v[] = new int[20];
  10.     int pares = 0 ;
  11.     int m5 = 0;
  12.     int negativos = 0;
  13.    
  14.     void pegaVetor(){
  15.         for (int i = 0; i < 20; i++) {
  16.             v[i] = Integer.parseInt(JOptionPane.showInputDialog("Insira um número: "));    
  17.         }
  18.     }
  19.    
  20.     void classificaVetor(){
  21.         for (int i = 0; i < 20; i++) {
  22.             if(v[i]% 2 == 0){
  23.                 pares++;
  24.             }
  25.             if(v[i]% 5 == 0){
  26.                 m5++;
  27.             }
  28.             if(v[i] < 0){
  29.                 negativos++;
  30.             }
  31.         }
  32.     }
  33.    
  34.     void informaClassificacao(){
  35.         System.out.println("Numeros pares no Vetor: " + pares + "\nNúmeros "
  36.                 + "multiplos de 5 no Vetor: " + m5 + "\nNúmeros negativos no "
  37.                 + "Vetor: " + negativos);
  38.     }
  39. }
  40.  
  41. //MAIN
  42.  
  43. package classificanumeros;
  44. public class ClassificaNumeros {
  45.     public static void main(String[] args) {
  46.         Classifica c1 = new Classifica();
  47.         c1.pegaVetor();
  48.         c1.classificaVetor();
  49.         c1.informaClassificacao();
  50.    
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement