Created
April 3, 2025 16:33
-
-
Save kurotori/02c960bb7e491c8d92a059dac6431986 to your computer and use it in GitHub Desktop.
Ejemplo de Algoritmos Básicos de JAVA - 01
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void main(String[] args) { | |
String opcion = ""; | |
String[] datos = new String[10]; | |
Scanner teclado = new Scanner(System.in); | |
//fori | |
for (int i = 0; i < datos.length; i++) { | |
datos[i] = ""; | |
} | |
while ( ! opcion.equals("X") ) { | |
System.out.println("Ingrese una opción:"); | |
System.out.println("A - Agregar dato"); | |
System.out.println("M - Mostrar datos"); | |
System.out.println("X - Salir"); | |
opcion = teclado.nextLine(); | |
switch (opcion) { | |
case "A": | |
String dato = ""; | |
System.out.println("Ingrese un dato:"); | |
dato = teclado.nextLine(); | |
for (int i = 0; i < datos.length; i++) { | |
if ( datos[i].length() < 1 ) { | |
datos[i] = dato; | |
System.out.println("Dato guardado en posicion " + i); | |
break; | |
} | |
} | |
break; | |
default: | |
break; | |
} | |
} | |
teclado.close(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment