'simple' for loop

so I'm kinda new to Java and a loop I need to write is just basically to start at 10, and go to 100 in steps of 10. but they need to be spaced like this
10 20
30 40
50 60
70 80
90 100

I know that if I just wanted them all in a line I could do
for(i=10; i<= 100; i+=10){
System.out.println(i);

How do I do the spacing? Any help or advice would be great. Thanks

Comments

  • : so I'm kinda new to Java and a loop I need to write is just
    : basically to start at 10, and go to 100 in steps of 10. but they
    : need to be spaced like this
    : 10 20
    : 30 40
    : 50 60
    : 70 80
    : 90 100
    :
    : I know that if I just wanted them all in a line I could do
    : for(i=10; i<= 100; i+=10){
    : System.out.println(i);
    :
    : How do I do the spacing? Any help or advice would be great. Thanks
    For the spacing you need to introduce an if-statement to select which "character" you want behind the number. Here's the code:
    [code]
    for(i=10; i<= 100; i+=10){
    if (i%20 == 0)
    System.out.println(i);
    else
    System.out.print(i+" ");
    }
    [/code]
  • : : so I'm kinda new to Java and a loop I need to write is just
    : : basically to start at 10, and go to 100 in steps of 10. but they
    : : need to be spaced like this
    : : 10 20
    : : 30 40
    : : 50 60
    : : 70 80
    : : 90 100
    : :
    : : I know that if I just wanted them all in a line I could do
    : : for(i=10; i<= 100; i+=10){
    : : System.out.println(i);
    : :
    : : How do I do the spacing? Any help or advice would be great. Thanks
    : For the spacing you need to introduce an if-statement to select
    : which "character" you want behind the number. Here's the code:
    : [code]:
    : for(i=10; i<= 100; i+=10){
    : if (i%20 == 0)
    : System.out.println(i);
    : else
    : System.out.print(i+" ");
    : }
    : [/code]:

    public class simplefor
    {
    public static void main(String []args)
    {
    for(int i=10; i<=90; i+=20)
    {
    int j= i+10;
    System.out.print(i+" "+j+"
    ");
    }
    }
    }


  • : so I'm kinda new to Java and a loop I need to write is just
    : basically to start at 10, and go to 100 in steps of 10. but they
    : need to be spaced like this
    : 10 20
    : 30 40
    : 50 60
    : 70 80
    : 90 100
    :
    : I know that if I just wanted them all in a line I could do
    : for(i=10; i<= 100; i+=10){
    : System.out.println(i);
    :
    : How do I do the spacing? Any help or advice would be great. Thanks

    Or even simpler...

    for (int i=10; i<=90; i+=20)
    System.out.print(i+" "+(i+10));
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories