Results 1 to 3 of 3

Thread: My vector code

  1. #1
    drico7041 is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default My vector code

    How do I make my code count the amount of 1's, 2's, 3's ... 98's and 99's in the vector. I'm having trouble completing this. Please help.
    Java Code:
     import java.util.*;
    import java.util.Vector;
    import java.util.Random;
    import javax.swing.JOptionPane;
    import java.util.Collections;
    import java.util.List;
    
    public class Count {
    
        public static void main(String[] arg) {
            String output;
            int[] anArray = new int [100];
            int a;
            Vector<Integer> vect = new Vector<Integer>(1,10000);
            {
                Random generator = new Random();
                for (int i = 1; i < 10000; i++) {
                    int rand = generator.nextInt(97);
                    vect.add(rand);
                    vect.add(Math.abs(generator.nextInt()) % 99);
                }
                //you can only sort it after you generated the random numbers
                Collections.sort(vect);
                for (int i = 1; i < vect.size(); i++) {
                    System.out.println(vect.get(i)+ 1);
                
           
            }
        }
        }
    }

  2. #2
    diamonddragon is offline Senior Member
    Join Date
    Jan 2012
    Posts
    210
    Rep Power
    3

    Default Re: My vector code

    Just to inform that Vector class is predecessor of ArrayList class.

  3. #3
    drico7041 is offline Member
    Join Date
    Jan 2012
    Posts
    2
    Rep Power
    0

    Default Re: My vector code

    I know. But unfortunately my teacher is making me use vectors..

Similar Threads

  1. Help Vector
    By nikosv in forum New To Java
    Replies: 4
    Last Post: 12-16-2010, 05:27 AM
  2. Vector<vector> loop thru
    By ocean in forum New To Java
    Replies: 11
    Last Post: 11-21-2009, 02:17 PM
  3. Replies: 1
    Last Post: 04-06-2009, 06:45 AM
  4. vector - get
    By natdizzle in forum New To Java
    Replies: 2
    Last Post: 01-02-2009, 04:09 AM
  5. Vector help
    By king_arthur in forum New To Java
    Replies: 3
    Last Post: 01-22-2008, 07:33 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •