+ 1

How to change the order of the output?

for example, my output comes like this:1 2 3 4 5 but i want the output to come like this 5 4 3 2 1 what should i do? thanks in advance.

16th Nov 2016, 8:58 AM
Ali Anando
Ali Anando - avatar
6 Réponses
+ 5
the easier way is store your output in an array.now print the array from last index using for Loop
16th Nov 2016, 9:06 AM
sai chander
sai chander - avatar
+ 5
int a[]={1,2,3,4,5}; for(int i=4;i >=0;i--) System.out.println(a[i]);
16th Nov 2016, 9:23 AM
sai chander
sai chander - avatar
+ 2
I guess you are using for loop to print output. I guess it's looking like this: for (int i = 1; i <= 5; i++) System.out.print(i); so if you want reverse input, just make for loop reversed: for(int i = 5; i >= 1; i--) System.out.print(i);
16th Nov 2016, 9:07 AM
Jakub Stasiak
Jakub Stasiak - avatar
+ 1
thanks @chander for you answer. can you please give me a example, it will be lot easier then.
16th Nov 2016, 9:16 AM
Ali Anando
Ali Anando - avatar
0
thanks for the answer @jakub i am using a for loop but its a bit hard to reverse the loop and actually i don't want to reverse the for loop. is there any other way to reverse the output?? thanks again
16th Nov 2016, 9:14 AM
Ali Anando
Ali Anando - avatar
0
It's the easiest way. Other solutions would be longer, slower and harder to understand. Just my opinion.
16th Nov 2016, 9:18 AM
Jakub Stasiak
Jakub Stasiak - avatar