fork download
  1. import java.util.*;
  2.  
  3. class VectOfLongs {
  4. private long[] theNumbers;
  5. private int size, capacity;
  6.  
  7. public VectOfLongs() {
  8. size = 0;
  9. capacity = 5;
  10. theNumbers = new long[capacity];
  11. }
  12.  
  13. public void printme()
  14. {
  15. for(long n : theNumbers)
  16. {
  17. System.out.format("%d ", n);
  18. }
  19. System.out.println("");
  20. }
  21.  
  22.  
  23. public void padVectorWithZeroes() {
  24. System.out.println(capacity);
  25. System.out.println(theNumbers.length);
  26.  
  27. for(int i=size; i<capacity; i++){
  28. theNumbers[i]=0;
  29. }
  30.  
  31. size++;
  32. }
  33.  
  34.  
  35.  
  36. public void insert(long l) {
  37. if (size==capacity) {
  38. long[] tmp = new long[capacity+5];
  39. capacity += 5;
  40. for (int i=0; i<size; i++)
  41. tmp[i] = theNumbers[i];
  42. theNumbers = tmp;
  43. }
  44. theNumbers[size++] = l;
  45. }
  46. }
  47.  
  48. public class Main {
  49. public static void main(String args[]) {
  50. VectOfLongs v = new VectOfLongs();
  51. v.insert(2); v.insert(-1); v.insert(-2);
  52. v.insert(4); v.insert(5); v.insert(3);
  53. System.out.println(v);
  54. //System.out.println(v.howManyOddAndPositive());
  55.  
  56. v.padVectorWithZeroes();
  57. v.printme();
  58. }
  59. }
Success #stdin #stdout 0.08s 381184KB
stdin
Standard input is empty
stdout
VectOfLongs@8e2fb5
10
10
2  -1  -2  4  5  3  0  0  0  0