Advertisement
Guest User

class Vector example

a guest
Oct 23rd, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. class easyVector<T> {
  4.     private T[] arr;
  5.     private static int count = 0;
  6.  
  7.     public static int getCount() {
  8.         return count;
  9.     }
  10.  
  11.     public easyVector(T[] array) {
  12.         arr = array.clone();
  13.         count++;
  14.     }
  15.  
  16.     public void print() {
  17.         for (int i = 0; i < arr.length; i++) {
  18.             System.out.print(arr[i] + " ");
  19.         }
  20.         System.out.println();
  21.     }
  22. }
  23.  
  24. public class Main {
  25.     public static Scanner in = new Scanner(System.in);
  26.  
  27.     public static void main(String[] args) {
  28.         Integer[] I = {11, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  29.         System.out.println(easyVector.getCount());
  30.         easyVector<Integer> a = new easyVector<>(I);
  31.         System.out.println(easyVector.getCount());
  32.         easyVector<Integer> b = new easyVector<>(new Integer[]{1, 6, 2, 7, 3, 5, 8});
  33.         System.out.println(easyVector.getCount());
  34.     }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement