Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Last active September 18, 2019 16:01
Show Gist options
  • Save parzibyte/68ce7c69746c25c5fba2dd95693e9200 to your computer and use it in GitHub Desktop.
Save parzibyte/68ce7c69746c25c5fba2dd95693e9200 to your computer and use it in GitHub Desktop.
class Main {
public static void main(String[] args) {
// Definir arreglo de 5 elementos
int[] edades = new int[5];
// Establecer elementos
edades[0] = 23;
edades[1] = 50;
edades[2] = 80;
edades[3] = 18;
edades[4] = 20;
// Definir arreglo y sus elementos
int[] numeros = new int[] { 1, 2, 3, 4, 5 };
// Arreglo de objetos
Mascota[] mascotas = new Mascota[2];
mascotas[0] = new Mascota("Maggie");
mascotas[1] = new Mascota("Panqué");
// Recorremos
for (int x = 0; x < edades.length; x++) {
System.out.printf("Edades[%d] = %d\n", x, edades[x]);
}
for (int x = 0; x < numeros.length; x++) {
System.out.printf("Numeros[%d] = %d\n", x, numeros[x]);
}
for (int x = 0; x < mascotas.length; x++) {
System.out.printf("Mascotas[%d] = %s\n", x, mascotas[x]);
}
}
}
class Mascota {
private String nombre;
public Mascota(String nombre) {
this.nombre = nombre;
}
@Override
public String toString() {
return "Mascota{" + "nombre='" + nombre + '\'' + '}';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment