Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.JOptionPane;
- public class Array_01 {
- public static void main(String[] args) {
- int[] tam = new int[5];
- int par=0, impar=0;
- int i=0;
- for(i=0;i<tam.length;i++)
- {
- int recebe = Integer.parseInt(JOptionPane.showInputDialog(i+" número: "));
- if(recebe%2==0){
- par++; // se for par, incrementa
- } else {
- impar++; // se for impar, incrementa
- }
- }
- int opcao = Integer.parseInt(JOptionPane.showInputDialog("Escolha a opcao: "+
- "\n[1] - Par"+"\n[2] - Impar"));
- switch(opcao)
- {
- case 1: for(i=0;i<tam.length;i++) { JOptionPane.showMessageDialog(null, par++); } break;
- case 2: for(i=0;i<tam.length;i++) { JOptionPane.showMessageDialog(null, impar++); } break;
- default:
- JOptionPane.showMessageDialog(null, "erro!!\nvocê digitou uma entrada inválida!");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement