Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Printing out 1-1000
#1
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!
My Blog | My Setup | My Videos | Have a wonderful day.
#2
Thanks for sharing it!!!!!!!!!!!!!1
The Power to Believe in Yourself is the Power to change the Fate!


Possibly Related Threads…
Thread Author Replies Views Last Post
  Printing out 1-1000 (inclusive) 0 1,952 Less than 1 minute ago
Last Post:
  Printing out 1-1000 (inclusive) 0 2,016 Less than 1 minute ago
Last Post:
  Printing out 1-1000 0 1,837 Less than 1 minute ago
Last Post:
  Printing out 1-1000 0 1,872 Less than 1 minute ago
Last Post:
  Printing out 1-1000 0 1,849 Less than 1 minute ago
Last Post:
  Printing out 1-1000 0 1,858 Less than 1 minute ago
Last Post:

Forum Jump:


Users browsing this thread: 1 Guest(s)