Skip to content

Commit 5e1d7f0

Browse files
committed
Ejercicio 1 vectores
1 parent 8f8bc2d commit 5e1d7f0

File tree

2 files changed

+76
-34
lines changed

2 files changed

+76
-34
lines changed

src/basesjava/BasesJava.java

Lines changed: 38 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
package basesjava;
66

77
import basesjava.EjercicioDespensa.Ejercicio_despensa;
8+
import basesjava.EjerciciosVectoresMatrices.*;
89
import basesjava.OperadorTernario.*;
10+
911
/**
1012
*
1113
* @author josue
@@ -16,7 +18,7 @@ public static void main(String[] args) {
1618

1719
// // Declaracion de Instancias
1820
// // TIpoVariables variables = new TIpoVariables();
19-
21+
2022
// // Ejercicio1 ejercicio1 = new Ejercicio1();
2123
// // EjercicioSwitch ejercicioSwitch = new EjercicioSwitch();
2224

@@ -25,10 +27,9 @@ public static void main(String[] args) {
2527
// // ejercicio.saludar();
2628
// // ejercicioSwitch.StructureOfSwitch();
2729

28-
2930
// // Llamando al método obtenerSaludo
3031
MetodosEjemplos ejercicio = new MetodosEjemplos();
31-
32+
3233
String saludo = ejercicio.obtenerSaludo("Josue");
3334
System.out.println(saludo);
3435

@@ -43,67 +44,69 @@ public static void main(String[] args) {
4344

4445
// operador Ternario
4546

46-
TernarioOperador ternario = new TernarioOperador();
47+
TernarioOperador ternario = new TernarioOperador();
4748
ternario.operador();
4849

49-
50-
// While
50+
// While
5151

5252
int contador = 0;
5353

5454
while( contador <= 10) {
5555

56-
System.out.println("Estoy en la vuelta: "+ contador);
57-
contador++;
56+
System.out.println("Estoy en la vuelta: "+ contador);
57+
contador++;
5858
}
5959

60-
6160
// While infinitos con estructuras repetitivas
6261

6362
boolean centinela = true;
6463

6564
while( centinela == true) {
66-
System.out.println("Estoy en la vuelta: "+ centinela);
67-
centinela = false;
65+
System.out.println("Estoy en la vuelta: "+ centinela);
66+
centinela = false;
6867
}
6968

70-
// Ciclo For
69+
// Ciclo For
7170

7271
for( int cont = 0; cont <= 10; cont++){
7372

74-
System.out.println("El valor es el siguiente " + cont);
73+
System.out.println("El valor es el siguiente " + cont);
7574

7675
}
7776

78-
79-
// Declararion de Vectores
77+
// Declararion de Vectores
8078

8179
int vector [] = new int [4];
8280
// int vector []; sin asignar el tamaño
8381

8482
// Asignaciond ( manual )
85-
vector[0] = 2;
86-
vector[1] = 50;
87-
vector[2] = 1223;
88-
vector[3] = 44;
89-
// vector[4] = 44; Esto genera un error ya que no es del mismo tamaño Index 4 out of bounds for length 4
83+
vector[0] = 2;
84+
vector[1] = 50;
85+
vector[2] = 1223;
86+
vector[3] = 44;
87+
88+
/*
89+
vector[4] = 44;
90+
(Esto genera un error ya que no es del mismo tamaño Index 4)
91+
out of bounds for length 4
92+
*/
9093

9194
System.out.println(vector);
9295

93-
// Recorrido
96+
// Recorrido
9497

9598
for( int i = 0; i < vector.length; i ++ ){
96-
System.out.println(vector[i]);
99+
System.out.println(vector[i]);
97100
}
98101

99-
// Matriz
102+
// Matriz
103+
104+
int matriz [][] = new int [3][3]; // 3 filas , 3 columnas
100105

101-
int matriz [][] = new int [3][3]; // 3 filas , 3 columnas
102-
103106
// matriz = [
104-
// [0, 0, 0], # Fila 0
105-
// [0, 0, 0], # Fila 1
106-
// [0, 0, 0] # Fila 2
107+
// [0, 0, 0], # Fila 0
108+
// [0, 0, 0], # Fila 1
109+
// [0, 0, 0] # Fila 2
107110
// ]
108111

109112
// Asignacion Manual
@@ -113,13 +116,14 @@ public static void main(String[] args) {
113116
matriz[1][1] = 1900;
114117
matriz[1][2] = 50;
115118

116-
117119
for (int i = 0; i < matriz.length; i++) {
118-
for (int j = 0; j < matriz[i].length; j++) {
119-
System.out.print(matriz[i][j] + " ");
120-
}
121-
System.out.println();
120+
for (int j = 0; j < matriz[i].length; j++) {
121+
System.out.print(matriz[i][j] + " ");
122+
}
123+
System.out.println();
122124
}
123-
}
124125

126+
Ejercicio1 findTheNumberEjercicio1 = new Ejercicio1();
127+
findTheNumberEjercicio1.manyTimesRepited();
128+
}
125129
}
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package basesjava.EjerciciosVectoresMatrices;
2+
import java.util.Scanner;
3+
4+
5+
public class Ejercicio1 {
6+
/*
7+
8+
Realizar un programa que permita cargar 15 numeros en un vector.
9+
Una vez cargados, se necestia que el programa cuente e informe por pantalla cuantas veces se cargo el numero 3
10+
11+
*/
12+
13+
public void manyTimesRepited() {
14+
15+
int numbers [] = new int [15];
16+
Scanner teclado = new Scanner(System.in);
17+
18+
for( int i = 0 ; i < numbers.length; i++) {
19+
System.out.println("Ingrese el valor: " + i );
20+
numbers[i] = teclado.nextInt();
21+
}
22+
23+
int counter = 0;
24+
25+
for( int i = 0; i < numbers.length; i++) {
26+
27+
if( numbers[ i ] == 3){
28+
counter++;
29+
}
30+
}
31+
32+
System.out.println("En el vector el numeros 3 esta repetido: "+ counter);
33+
34+
}
35+
36+
37+
38+
}

0 commit comments

Comments
 (0)