My task is : Perform a program that generates 100 random numbers (Between 0 and 100) by saving them in a vector. Then show the 10 majors. The repeated ones leave. What i did is :
public static void main (String[] args) {
Random rnd=new Random();
int [] vec=new int [10];
int largest=vec[0];
for (int i = 0; i < vec.length; i++)
vec[i]=rnd.nextInt(100);
for (int i = 0; i < vec.length; i++) {
if (vec[i] > largest) {
largest = vec[i];
}
/*if (vec[i]>vec[0]){
System.out.print(vec[i]+" ");*/
System.out.print(largest);
}
}
Aucun commentaire:
Enregistrer un commentaire