vendredi 26 juillet 2019

Random Number generator in a range and then print length of the sequence

I want the application to create a sequence that generates a series of random numbers from 0 to 9 util a 0 is generated and then display the length of the sequence of the numbers. Right now my program only prints 0 or 9 as I don't know the random number generator method.My question is how do I generate a random integer between 0 and 9(inclusive) unit a 0 is generated.

import java.util.Random;
import java.util.ArrayList;

public class Sequence {
   public static void main(String[] args) {
       ArrayList<Integer>  lista = new ArrayList<Integer>();
       lista.add(0, 9);



       Random r = new Random();
       System.out.println(lista.get(r.nextInt(lista.size())));
      }
   }




Aucun commentaire:

Enregistrer un commentaire