Skip to content

Instantly share code, notes, and snippets.

@joanmolinas
Last active August 29, 2015 14:17
Show Gist options
  • Save joanmolinas/69ce9c6a56e2b54d3c7d to your computer and use it in GitHub Desktop.
Save joanmolinas/69ce9c6a56e2b54d3c7d to your computer and use it in GitHub Desktop.
//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