BP Forums
Printing out 1-1000 - Printable Version

+- BP Forums (https://bpforums.info)
+-- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=55)
+--- Forum: Archived Forums (https://bpforums.info/forumdisplay.php?fid=56)
+---- Forum: Java (https://bpforums.info/forumdisplay.php?fid=19)
+---- Thread: Printing out 1-1000 (/showthread.php?tid=524)



Printing out 1-1000 - brandonio21 - 05-03-2012

I got a small challenge from a Youtube user, as follows:
Quote:Write a program to print out all of the numbers between 1 and 1000 inclusive. Each number should be seperated by a space. There should only be 10 numbers printed on any given line, i.e. every 10th number should be followed by the new line character.

So, here's the solution!
Code:
for (int i = 1; i <= 1000; i++) {
    System.out.print(i + " ");

    if (i % 10 == 0)
        System.out.println();
}

Pastebin version: http://pastebin.com/M1EZ73nw

Just thought that I would share!


Re: Printing out 1-1000 - Himansh - 05-04-2012

Thanks for sharing it!!!!!!!!!!!!!1