+ 1

How to print 5 numbers per line?

29th Dec 2018, 9:33 AM
Far Na
Far Na - avatar
4 Answers
+ 12
You could do somthing like this in java.. for(int i = 1; i < 21;i++){ System.out.print(i+" "); if(i%5==0){System.out.println(); } } if you want to keep the 0 use i-1+" " in the print statment theres also a shorthand way if your intrested for(int i =1; i < 21;i++){ System.out.print(i%5!=0?i:i+"\n"); } 😉👍
29th Dec 2018, 9:45 AM
D_Stark
D_Stark - avatar
+ 4
It's easier to help you if you let us know what language you're asking about, maybe even give an example output etc.
29th Dec 2018, 10:02 AM
Anna
Anna - avatar
+ 1
(answering with java syntax,change as suitable) keep an inner loop like for(j=0;j<5;j++) then ... System.out.print(whatever number u want to print)... and outside the loop write a blank println statement to go to new line
29th Dec 2018, 9:37 AM
Asirap
0
Java
29th Dec 2018, 10:06 AM
Far Na
Far Na - avatar