How could I reverse the output of this java code I made this code: public static
ID: 3567693 • Letter: H
Question
How could I reverse the output of this java code
I made this code:
public static int Series (int s){
int i = s;
int iplusone = s+1;
if(s == 0){
System.exit(0);
}
else{
System.out.print(i + "/" + iplusone + ", ");
}
return Series(s-1);
}
Which would give i/(i+1) for an int, s, until s=0. Which is what I want, but the output is in reverse. For example with 5 it puts,
5/6, 4/5, 3/4, 2/3, 1/2
What could I do to reverse this so with 5 it would read
1/2, 2/3, 3/4, 4/5, 5/,6
I'm still a beginner with java, so nothing crazy please! Thank you. The method must stay recursive (it's a requirement of the assignment).
Explanation / Answer
public static void Series (int s){
int i = s;
int iplusone = s+1;
if(s == 0){
return ;
}
Series(s-1);
System.out.print(i + "/" + iplusone + ", ");
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.