Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Practicas;
- import java.util.Scanner;
- import java.util.Arrays;
- /**
- *
- * @author Uriel Cambron Hernandez
- * @ITSCH Junior Researcher
- */
- public class Promedios {
- public static void main(String[] args) {
- Scanner xr = new Scanner(System.in);
- Promedios obj = new Promedios();
- int dates[];
- int size = xr.nextInt();
- dates = new int[size];
- for (int i = 0; i < size; i++) {
- dates[i] = (int) (Math.random() * (size * 2)) + 1;
- System.out.print(dates[i] + " ");
- }
- Arrays.sort(dates);
- System.out.println("");
- for (int i = 0; i < size; i++) {
- //dates[i] = (int) (Math.random() * (size * 2)) + 1;
- System.out.print(dates[i] + " ");
- }
- int prom = obj.Promedio(dates);
- System.out.println("\nMedia: " + prom);
- System.out.println("Mediana : " + obj.Mediana(dates));
- System.out.println("Moda: " + obj.Moda(dates));
- System.out.println("Minimo Comun Multiplo: " + obj.MinimoComunMultiplo(dates));
- System.out.println("Maximo Comun Divisor: " + obj.MaximoComunDivisor(dates));
- System.out.println("Relacion Con Media: " + obj.RelacionConMedia(dates, prom));
- }
- public int Promedio(int[] dates) {
- int promedio = 0, suma = 0;
- for (int x : dates) {
- suma += x;
- }
- promedio = (suma / dates.length);
- return promedio;
- }
- public int Mediana(int[] dates) {
- int med = 0;
- if (!(dates.length % 2 == 0)) {
- med = (dates.length / 2);
- } else {
- med = (dates.length / 2) - 1;
- }
- med = dates[med];
- return med;
- }
- public int Moda(int[] dates) {
- int moda = 0;
- int coincidencias[] = new int[dates.length];
- for (int x = 0; x < dates.length; x++) {
- for (int y = x; y < dates.length; y++) {
- if (dates[x] == dates[y]) {
- coincidencias[x]++;
- }
- }
- }
- int mayor = coincidencias[0];
- for (int i = 1; i < dates.length; i++) {
- if (coincidencias[i] > mayor) {
- mayor = i;
- }
- }
- moda = dates[mayor];
- return moda;
- }
- public int MinimoComunMultiplo(int[] dates) {
- int mcm = 1;
- for (int i : dates) {
- for (int x : dates) {
- if (x % i == 0) {
- mcm = i;
- } else {
- mcm = 1;
- break;
- }
- }
- if(mcm>1){
- break;
- }
- }
- return mcm;
- }
- public int MaximoComunDivisor(int[] dates) {
- int mcd = 1;
- for (int i = 1; i <= dates[dates.length - 1]; i++) {
- for (int x : dates) {
- if (x % i == 0) {
- mcd = i;
- } else {
- mcd = 1;
- break;
- }
- }
- if(mcd>1){
- break;
- }
- }
- return mcd;
- }
- public String RelacionConMedia(int[] dates, int media) {
- String state = "";
- int uppers = 0, lowers = 0;
- for (int x : dates) {
- if (x > media) {
- uppers++;
- } else {
- lowers++;
- }
- }
- if (uppers > lowers) {
- state = "Valores Altos";
- } else {
- state = "Valores Bajos";
- }
- return state;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement