Hey, I was having trouble making my vector print out randomly generated numbers in ascending order. Can I please get some help?.
This is my assignment "Write a program name count.java that will use a Vector to store 10,000 randomly generated numbers (ranging from 1 to 99)
Now sort the vector in ascending order. Also, count the amount of 1's, 2's, 3's ... 98's and 99's in the vector.
1. The program should display the sorted vector on the screen.
2. The program should also display the amount of 1's, 2's, ..... etc. on the screen. "
And this is the code I have so far.
import java.util.*;
import java.util.Vector;
import java.util.Random;
import javax.swing.JOptionPane;
public class Count {
public static void main(String[] args) {
String output;
Vector<Integer> vect = new Vector<Integer>(10000);
{
Collections.sort(vect);
Random generator = new Random();
for (int i = 0; i < 10000; i++)
{
int rand = generator.nextInt(98)+1;
vect.add(rand);
vect.add(Math.abs(generator.nextInt()) % 100);
System.out.println(vect.get(i));
}
}
}
}