-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVectors.java
More file actions
59 lines (51 loc) · 1.83 KB
/
Vectors.java
File metadata and controls
59 lines (51 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Main.java to edit this template
*/
package javaexercises;
import java.util.Scanner;
/**
*
* @author Laura Gómez Ruiz
*/
public class Vectors {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
/************
STATIC VECTOR
************/
int numbers [] = new int [5];
numbers [0] = 5;
numbers [1] = 220;
numbers [2] = 8;
numbers [3] = 458;
numbers [4] = 22;
System.out.println("Static Vector:");
System.out.print("[" + numbers[0] + "]");
System.out.print("[" + numbers[1] + "]");
System.out.print("[" + numbers[2] + "]");
System.out.print("[" + numbers[3] + "]");
System.out.print("[" + numbers[4] + "]");
System.out.println("");
System.out.println("");
/*************
DINAMIC VECTOR
*************/
int vectorLength = 0;
Scanner keyboard = new Scanner (System.in);
System.out.println("How many numbers do you want to introduce?");
vectorLength = keyboard.nextInt();
int dinamicVector [] = new int [vectorLength];
System.out.println("Dinamic Vector:");
for (int i = 0; i < dinamicVector.length; i++) {
System.out.println("Introduce the number at " + i + " position: ");
dinamicVector[i] = keyboard.nextInt();
}
System.out.print("Our Dinamic Vector: ");
for (int i = 0; i < dinamicVector.length; i++) {
System.out.print("[" + dinamicVector[i] + "]");
}
}
}