Last active
January 29, 2021 14:49
-
-
Save daom89/d001473b3e3df6c6a45d7a37dc37339f to your computer and use it in GitHub Desktop.
Ejemplo Vectores
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
/* | |
* To change this license header, choose License Headers in Project Properties. | |
* To change this template file, choose Tools | Templates | |
* and open the template in the editor. | |
*/ | |
package com.mycompany.ejemplovectores; | |
import javax.swing.JOptionPane; | |
/** | |
* | |
* @author grani | |
*/ | |
public class EjemploVector { | |
public static void main(String[] args) { | |
//Variable | |
//String Nombre = "Diego"; | |
//JOptionPane.showMessageDialog(null, "Su Nombre es: "+Nombre, "Nombre Usuario", JOptionPane.ERROR_MESSAGE); | |
//Vector | |
//String VectorNombres[] = {"Juan", "Pedro","Luis","Miguel"}; | |
/*String VectorNombres[] = new String [4]; //OJO DEFINE TAMAÑO | |
VectorNombres[0] = "Juan"; | |
VectorNombres[1] = "Pedro"; | |
VectorNombres[2] = "Luis"; | |
VectorNombres[3] = "Miguel"; | |
*/ | |
int NumeroAlumnos = Integer.parseInt(JOptionPane.showInputDialog(null, "Ingrese la cantidad de alumnos del nombre: ", "Numero de Alumnos", JOptionPane.QUESTION_MESSAGE)); | |
String VectorNombres[] = new String [NumeroAlumnos]; | |
String VectorEdades[] = new String [NumeroAlumnos]; | |
//Llenando el Array | |
for (int i = 0; i < NumeroAlumnos; i++) { | |
VectorNombres[i] = JOptionPane.showInputDialog(null, "Ingrese el nombre del alumno "+(i+1)+": ", "Nombre Alumno", JOptionPane.QUESTION_MESSAGE); | |
VectorEdades[i] = JOptionPane.showInputDialog(null, "Ingrese la edad del alumno "+(i+1)+": ", "Edad Alumno", JOptionPane.QUESTION_MESSAGE); | |
} | |
for (int i = 0; i < 10; i++) { | |
} | |
int NuemeroDeVeces = 0; | |
while (NuemeroDeVeces < 10) { | |
NuemeroDeVeces++; | |
} | |
do { | |
NuemeroDeVeces++; | |
} while (NuemeroDeVeces < 10); | |
//Mostrando el Array | |
String DatosMensaje = ""; | |
for (int i = 0; i < NumeroAlumnos; i++) { | |
DatosMensaje = DatosMensaje+" Nombres: "+VectorNombres[i]+" y Edad: "+VectorEdades[i]+"\n"; | |
} | |
JOptionPane.showMessageDialog(null, "Los alumnos se llaman: \n"+DatosMensaje, "Nombre Usuario", JOptionPane.INFORMATION_MESSAGE); | |
//int Posicion = Integer.parseInt(JOptionPane.showInputDialog(null, "Ingrese la posicion del nombre: ", "Imprimir Nombre", JOptionPane.QUESTION_MESSAGE)); | |
//JOptionPane.showMessageDialog(null, "Su Nombre es: "+VectorNombres[Posicion], "Nombre Usuario", JOptionPane.ERROR_MESSAGE); | |
/* | |
for (int i = 0; i <= 3; i++) { | |
JOptionPane.showMessageDialog(null, "Su Nombre es: "+VectorNombres[i], "Nombre Usuario", JOptionPane.ERROR_MESSAGE); | |
}*/ | |
/*String Alumnos [] = new String[5]; | |
String TempName = ""; | |
JOptionPane.showMessageDialog(null, "Sistema de registro de ganadores", "Registro de Ganadores", JOptionPane.INFORMATION_MESSAGE); | |
for (int i = 0; i < 5; i++) { | |
TempName = JOptionPane.showInputDialog(null, "Ingrese el nombre del alumno "+(i+1)+": ", "Nombre Alumno", JOptionPane.QUESTION_MESSAGE); | |
Alumnos[i] = TempName; | |
} | |
JOptionPane.showMessageDialog(null, "Los Nombres de los ganadores son: ", "Registro de Ganadores", JOptionPane.INFORMATION_MESSAGE); | |
for (int i = 0; i < 5; i++) { | |
JOptionPane.showMessageDialog(null, "Ganador "+(i+1)+": "+Alumnos[i], "Registro de Ganadores", JOptionPane.INFORMATION_MESSAGE); | |
}*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment