Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CLASSE
- package classificanumeros;
- import javax.swing.JOptionPane;
- public class Classifica {
- int v[] = new int[20];
- int pares = 0 ;
- int m5 = 0;
- int negativos = 0;
- void pegaVetor(){
- for (int i = 0; i < 20; i++) {
- v[i] = Integer.parseInt(JOptionPane.showInputDialog("Insira um número: "));
- }
- }
- void classificaVetor(){
- for (int i = 0; i < 20; i++) {
- if(v[i]% 2 == 0){
- pares++;
- }
- if(v[i]% 5 == 0){
- m5++;
- }
- if(v[i] < 0){
- negativos++;
- }
- }
- }
- void informaClassificacao(){
- System.out.println("Numeros pares no Vetor: " + pares + "\nNúmeros "
- + "multiplos de 5 no Vetor: " + m5 + "\nNúmeros negativos no "
- + "Vetor: " + negativos);
- }
- }
- //MAIN
- package classificanumeros;
- public class ClassificaNumeros {
- public static void main(String[] args) {
- Classifica c1 = new Classifica();
- c1.pegaVetor();
- c1.classificaVetor();
- c1.informaClassificacao();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement