-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain.java
More file actions
90 lines (59 loc) · 2.05 KB
/
Main.java
File metadata and controls
90 lines (59 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// TAREA - 1 ---------------
public class Main {
public static void main(String[] args) {
int[] numeros = {10, 3, 5, 6};
int diferencia = calcularDiderencia(numeros);
System.out.println(" La diferencia ente el digito mas grande i el mas pequeño es: " + diferencia);
}
public static int calcularDiderencia(int[] arr) {
if (arr == null || arr.length != 4)
throw new IllegalArgumentException(" El array tiene que tener exactamente 4 digitos");
int max = arr[0];
int min = arr[0];
for (int i = 1; i < arr.length; i++) {
if (arr[i] < max) {
min = arr[i];
}
}
return max - min;
}
}
// TAREA - 2 ---------------------
public class Main {
public static void main(String[] args) {
int[] numeros = {34, 12, 5, 22, 64};
encontrarMinimos(numeros);
}
public static void encontrarMinimos(int[] arr){
if (arr == null || arr.length != 5){
throw new IllegalArgumentException(" el array debe tener 5 numeros exactamente");
}
int minimo = Integer .MAX_VALUE;
int minimo2 = Integer .MAX_VALUE;
for (int i = 0; i < arr.length; i++) {
if (arr[i] < minimo) {
minimo2 = minimo;
minimo = arr[i];
} else if (arr[i] < minimo2 && arr[i] != minimo){
minimo2 = arr[i];
}
}
}
}
// TAREA - 3 -------------------
public class Main {
public static void main(String[] args) {
int x = 3;
int y = 4;
double resultado = calcularExpresion(x, y);
System.out.println(" El resultado de la expresion es: " + resultado);
}
public static double calcularExpresion(int x, int y){
if (5 - x == 0) {
throw new ArithmeticException("La expresion (5 - x) es igual a cero.");
}
double parteInterna = (4.0 * y) / (5 - x);
double resultado = Math.pow(x, 2) * Math.pow(parteInterna, 2);
return resultado;
}
}