Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- import java.util.ArrayList;
- public class ejercicio4 {
- Scanner Scanner= new Scanner(System.in);
- public static void main(String[] args) {
- ArrayList<Integer> vec= new ArrayList<Integer> ();
- float prom=0;
- CargarArray(vec);
- prom = Promedio(vec);
- ValoresMenores(vec,prom);
- }
- public static void CargarArray(ArrayList vec) {
- Scanner Scanner= new Scanner(System.in);
- int elemento = 0;
- String opc;
- do {
- System.out.println("Elemento: "+ vec.size());
- elemento= Scanner.nextInt();
- vec.add(elemento);
- System.out.println("¿Desea Continuar?(Si/No)");
- opc= Scanner.next();
- } while (opc.equalsIgnoreCase("Si"));
- }
- public static float Promedio(ArrayList vec) {
- int i;
- int suma=0;
- for (i=0; i<vec.size(); ++i) {
- suma= suma + (int)vec[i];
- }
- float prom= suma/vec.size();
- System.out.println("Promedio de los Numeros Ingresados: "+ prom);
- return prom;
- }
- public static void ValoresMenores( ArrayList vec,float prom) {
- int i=0;
- int cont=0;
- for (i=0; i<vec.size(); ++i) {
- if ((int)vec[i] < prom) {
- cont= cont +1;
- }
- }
- System.out.println("Valores Menores al Promedio: "+ cont);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement