+ 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.
6 Réponses
+ 5
the easier way is store your output in an array.now print the array from last index using for Loop
+ 5
int a[]={1,2,3,4,5};
for(int i=4;i >=0;i--)
System.out.println(a[i]);
+ 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);
+ 1
thanks @chander for you answer. can you please give me a example, it will be lot easier then.
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
0
It's the easiest way. Other solutions would be longer, slower and harder to understand. Just my opinion.