0

I`m working on java with a simple println line..So my question is.. Is there a way to print using println..then Back again to print in the 1st line using also println .. for example I want the out put like this

1 5
2 4
3 3
4 2
5 1

the 1st column is the output of this line

System.out.println("1\n2\n3\n4\n5");

I want it to finish the 1st print line then print the 2nd column but when I use this line

System.out.println("5\n4\n3\n2\n1");

It want print it the way I want

Is there any way to do that

Rajaprabhu Aravindasamy
  • 66,513
  • 17
  • 101
  • 130
noon
  • 21
  • 1
  • 2
  • 1
    No, the console cannot be rewound backwards to write additional data to previously output and terminated lines. – Jim Garrison Mar 12 '16 at 07:20
  • 1
    No. println() print a line of text. So use a `List` (for example) in memory, and print each IntegerPair as a line. It's up to you to transform your 2 columns of 5 numbers into 5 rows of two numbers. – JB Nizet Mar 12 '16 at 07:22
  • you helped me a lot thank you – noon Mar 12 '16 at 07:35

1 Answers1

1

No it's not possible. If you print to the console you have to do it line by line. So you have to think first what you want to print and build up your strings accordingly in advance.

Raphael Roth
  • 26,751
  • 15
  • 88
  • 145