Advertisement
MaTias0258

TPNº1_4

Sep 14th, 2022
856
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.42 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3.  
  4. public class TPN1_4 {
  5.  
  6.     public static void main(String[] args) {
  7.         int suma=0,cont=0,cont2=0;
  8.         double promedio=0;
  9.      
  10.         try{
  11.         Scanner sc = new Scanner(System.in);
  12.         System.out.print("Ingrese N cantidad :");
  13.         int n = sc.nextInt();
  14.        
  15.         ArrayList<Integer> vectorDinamico = new ArrayList<>();
  16.         int a = 0, b = 1, c;
  17.         vectorDinamico.add(a);
  18.         vectorDinamico.add(b);
  19.        
  20.         for(int i = 2; i < n; i++) {
  21.             c = b + a;
  22.             a = b;
  23.             b = c;
  24.             vectorDinamico.add(c);
  25.         }
  26.         System.out.println(vectorDinamico);
  27.  
  28.         for (Integer i : vectorDinamico) {
  29.             if(i%2==0) {
  30.                 suma +=i;
  31.             }
  32.             else {
  33.                 cont++;
  34.             }
  35.          promedio+=i;
  36.         }
  37.         for (int i = 0; i < vectorDinamico.size(); i++) {
  38.             if(vectorDinamico.get(i) > promedio/vectorDinamico.size() ) {
  39.                 cont2++;
  40.             }
  41.         }
  42.        
  43.         System.out.println("la suma de los numeros pares : "+suma);
  44.         System.out.println("Cantidad de numeros impares : "+cont);
  45.         System.out.println("Promedio de los terminos generados : "+promedio/vectorDinamico.size());
  46.         System.out.println("Cantidad de numeros mayores al promedio : "+cont2);
  47.         }catch (Exception e){
  48.             System.out.println("ERROR: El valor ingresado no es valido solo numeros ");
  49.         }
  50.     }  
  51.        
  52.        
  53.  
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement