[1] Your code actually prints 101 numbers. Embrace the logic computers (and java) applies to loops and 'the fences' (the start and end): The first number is inclusive, the second is exclusive. By doing it that way, you just subtract the two to know how many items there are. so, for (int count = 0; count < 100; count++) - that loops 100 times. Using <= would loop 101 times.
[2] You're making this way too complicated by focusing on the notion of 'there must be a space in between 2', as if the 2 is important. What you really want is just 'after every random number, print a space'. The only downside is that this prints an extra space at the end, which probably doesn't matter:
for (int count = 0; i < 100; count++) { System.out.print(randomNum + " "); }
is all you actually needed. No need to involve printf:
I know I need to use the printf function
No, you don't. No idea why you concluded this. It's overkill here.
If you don't want the extra space.. simply don't print it for the last number:
for (int count = 0; i < 100; count++) { System.out.print(randomNum); if (count < 99) System.out.print(" "); }
[3] You mention that the code shuold print it all 'on one line', which perhaps suggests the line also needs to actually be a line. Add, at the very end, after the loop, System.out.println() to also go to a newline before you end.
int[100]and then turn the array into a string usingArrays.toStringand replacing the commas with spaces. Or, alternatively, print your number followed by a space, because that last space added to the last number won't matter.10 21 10 5 46 43 27 23 30 32 50 40 35 45 30 47 7 30 9 15 17 25 41 31 37 7 43 49 41 7 3 40 46 37 17 16 20 21 25 26 27 30 11 0 34 40 17 23 35 50 49 5 31 42 45 31 30 49 30 18 44 0 24 30 8 7 43 39 26 39 37 29 5 47 18 41 1 17 2 46 48 33 45 8 23 49 27 39 28 14 19 36 40 5 10 35 46 26 29 0 39?0 01 12 23 34 45 56 67 78 89 910 1011 11...and so on (it prints the generated number, a space, the exact same number, and then the next loop will immediately follow on, no space, with the next, in the same way).randomtag, the question remains unchanged whether the elements are random or not. It’s about formatting, not generating randomness.