samedi 3 septembre 2022

How would you go about adding a space between every random number?

I'm trying to get the console to output 100 random numbers between 0 and 50, all on the same line with a space between each. I have everything but the formatting for the space. I know I need to use the printf function, but am completely lost on how to properly impliment it. This is what I have so far, but the output formatting is incorrect.

public static void main(String[] args) {
  Random rand = new Random();
  for (int count = 0; count <=100; count++)
  {
    int randomNum = rand.nextInt(51);
    System.out.printf("%1d %1d", randomNum, randomNum);
  }
}



Aucun commentaire:

Enregistrer un commentaire