Last active
August 29, 2015 14:17
-
-
Save joanmolinas/69ce9c6a56e2b54d3c7d to your computer and use it in GitHub Desktop.
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
//Module of a vector | |
Vector<Integer> moduleVector = new Vector<Integer>(10); | |
for (int i = 0; i < 10; i++) { | |
moduleVector.add(randInt(-100, 100)); | |
} | |
double module = 0; | |
for (Integer i : moduleVector) { | |
module += Math.pow(i, 2); | |
} | |
module = Math.sqrt(module); | |
//Vector with Iterator | |
Vector<Integer> marks = new Vector<Integer>(); | |
for (int i = 0; i < 10; i++) { | |
marks.add(randInt(-100, 100)); | |
} | |
Iterator<Integer> iterator = marks.iterator(); | |
while(iterator.hasNext()) { | |
System.out.println(iterator.next()); | |
} | |
//Random number | |
public Integer randInt(int min, int max) { | |
Random r = new Random(); | |
return r.nextInt((max-min) +1 ) + min; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment