+ 6

how does cursor move to another line after printing 2????

public class Program { public static void main(String[] args) { int[ ] primes = {2, 3, 5, 7}; for (int t: primes) { System.out.println(t); } } } output is: 2 3 5 7

9th Jun 2019, 5:20 AM
Aditya Tiwari
Aditya Tiwari - avatar
2 Answers
+ 7
Because you have used System.out.println(t). This statement moves cursor to new line after printing the line You can use System.out.print(t) if you want all numbers in one line
9th Jun 2019, 5:49 AM
Deepak Kumar
Deepak Kumar - avatar
+ 3
U are using the println word which prints a line and then moves to another line. If you want to print it in one line then use the word print instead of println
9th Jun 2019, 5:51 AM
Ultarsonic