Advertisement
Chanchoveloz

Crear y cargar un vector ( arreglo, array)

Sep 25th, 2016
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. // Declarar un vector, cargarlo y luego mostrarlo en pantalla
  2. import java.util.Scanner;
  3. public class bloque41 {
  4.  
  5. public static void main(String[] args) {
  6.  
  7.  
  8. // Declaración del vector
  9. int[] vec= new int[5]; // vector de nombre vec de 5 elementos
  10.  
  11. Scanner S = new Scanner (System.in);
  12.  
  13. // Para cargar el vector
  14. for(int i=0; i<5; i++) {
  15. System.out.print("Entre un número entero: ");
  16. vec[i]= S.nextInt();
  17. }
  18.  
  19. //Para mostrarlo en pantalla
  20. for(int i=0; i<5; i++){
  21. System.out.print(vec[i]+", ");
  22. }
  23. }
  24.  
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement