forked from SimonRamos88/POO
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
128 lines (96 loc) · 3.61 KB
/
Copy pathApp.java
File metadata and controls
128 lines (96 loc) · 3.61 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
package MyappJava.src;
public class App {
static int numeros[]= new int[]{1,2,3,4,5,6,7,8,9} ;
static int respuesta_cerveza[] = new int[3];
static int cervezas [][]=new int[3][3];
static char respuesta_cafe[]= new char[4];
static char letras[]=new char[]{'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p'};
static char cafes[][]=new char[4][4];
public static void main(String[] args) throws Exception {
System.out.println("Hello, World!");
System.out.println(holaMundo());
llenar_cervezas();
llenar_cafes();
imprimir();
diagonal_superior();
diagonal_inferior();
}
public static String holaMundo() {
String hola = "Hola mundo";
return hola;
}
static void llenar_cervezas(){
//En esta funcion lo que hacemos es llenar la matriz de cervezas con los numeros del 1 al 9
//La variable a nos sirve como contador para poner los numeros
int a = 0;
for(int i = 0; i< 3; i++){
for(int j=0; j<3; j++){
cervezas[i][j]=numeros[a] ;
a++;
}
}
}
static void imprimir(){
//En esta funcion imprimimos las matrices para asegurarnos de que todo est� bien
System.out.println("Cervezas");
System.out.println("\n");
for(int i = 0; i< 3; i++){
for(int j=0; j<3; j++){
System.out.print("| "+cervezas[i][j]+" |");
}
System.out.println("\n");
}
System.out.println("\n");
System.out.println("Cafes" + "\n");
for(int a = 0; a< 4; a++){
for(int b=0; b<4; b++){
System.out.print("| "+cafes[a][b]+" |");
}
System.out.println("\n");
}
}
static void diagonal_superior(){
//En esta funcion hayamos la diagonal superior, que se encuentra cuando i==j
for(int i = 0; i< 3; i++){
for(int j=0; j<3; j++){
if(i==j){
respuesta_cerveza[i] = cervezas[i][j];
}
}
}
System.out.println("\n");
System.out.println("La respuesta (cervezas) es: ");
for(int k = 0; k<3; k++){
System.out.print(respuesta_cerveza[k]+" ");
}
}
//codigo para problema 2
static void llenar_cafes(){
//Aqui llenamos la matriz del cafe con un arreglo que contiene las letras. a nos sirve como contador del arreglo.
int a = 0;
for(int i = 0; i< 4; i++){
for(int j=0; j<4; j++){
cafes[i][j]=letras[a] ;
a++;
}
}
}
static void diagonal_inferior(){
//para hallar la diagonal inferior, debemos iniciar desde la ultima fila y ascender (i--), e iniciar desde la primera columna y aumentar (j++)
//se halla cuando j+i == 3.
//j nos sirve para mostrar en orden ascendente las letras. Puesto que si usaramos i tendr�amos un orden descendente xd
for(int i = 3; i >= 0; i--){
for(int j = 0; j<4; j++){
if(i+j==3){
respuesta_cafe[j] = cafes[i][j];
}
}
}
System.out.println("\n");
System.out.println("La respuesta (cafes) es: ");
for(int k = 0; k<4; k++){
//comentario
System.out.print(respuesta_cafe[k]+" ");
}
}
}