Advertisement
Andrei_M

Ass_3.java

Oct 23rd, 2019
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.93 KB | None | 0 0
  1. class MyString
  2. {
  3.     private int vector[];
  4.     private int j , ct = 0;
  5.    
  6.     public MyString(int values[])
  7.     {
  8.         for(int i = 0; i < values.length; i++)
  9.         {
  10.             vector[i] = values[i];
  11.             j = i;
  12.         }
  13.     }
  14.    
  15.     public int length()
  16.     {
  17.         return j;
  18.     }
  19.    
  20.     public int valueAt(int position)
  21.     {
  22.         return (vector[position] != null) ? vector[position] : -1;
  23.        
  24.     }
  25.    
  26.     public boolean contains(int value)
  27.     {
  28.         for(int i = 0; i < vector.length; i++)
  29.         {
  30.             if(vector[i] == value)
  31.                 return true;
  32.         }
  33.         return false;
  34.     }
  35.    
  36.     public int count(int value)
  37.     {
  38.         for(int i = 0; i < vector.length; i++)
  39.         {
  40.             if(vector[i] == value)
  41.                 ct++;
  42.         }
  43.         return ct;
  44.     }
  45.    
  46.     public String toString()
  47.     {
  48.         String buffer = "";
  49.         for(int i = 0; i < vector.length; i++)
  50.         {
  51.             buffer += " " + vector[i];
  52.         }
  53.         return buffer;
  54.     }
  55. }
  56.  
  57.  
  58.  
  59. public class Main {
  60.  
  61.     public static void main(String[] args) {
  62.         // TODO Auto-generated method stub
  63.  
  64.     }
  65.  
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement