Skip to content

Instantly share code, notes, and snippets.

@kurotori
Created April 3, 2025 16:33
Show Gist options
  • Save kurotori/02c960bb7e491c8d92a059dac6431986 to your computer and use it in GitHub Desktop.
Save kurotori/02c960bb7e491c8d92a059dac6431986 to your computer and use it in GitHub Desktop.
Ejemplo de Algoritmos Básicos de JAVA - 01
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