hi all
i have a with my counter that starts at a value then for each step through the loop it should go down by one. ok the trial data i have when i run this program, and i have checked and rechecked it to make sure that the test data has the expected values
i=3
revline[0]=a
[1]=s
[2]=d
[3]=f
output:
3
Process completed.
if I move the second System.out.prin t(i); above the i--; then it will print a 3 so I think that the i--; line is incorect but I tried i = i - 1; and that didn't work either so I am at a total loss, the remainder of my code is below,
this is a homework assignment and I am not trying to cheat just figure out my error, anyway the assignment is to get a string from a user then print it reversed
thanks
eric
i have a with my counter that starts at a value then for each step through the loop it should go down by one. ok the trial data i have when i run this program, and i have checked and rechecked it to make sure that the test data has the expected values
i=3
revline[0]=a
[1]=s
[2]=d
[3]=f
Code:
System.out.println(i);
while(i>=0)
{
System.out.print(revline[i]);
i--;
System.out.print(i);
}
3
Process completed.
if I move the second System.out.prin t(i); above the i--; then it will print a 3 so I think that the i--; line is incorect but I tried i = i - 1; and that didn't work either so I am at a total loss, the remainder of my code is below,
this is a homework assignment and I am not trying to cheat just figure out my error, anyway the assignment is to get a string from a user then print it reversed
Code:
/**
* @(#)asg5.java
*
* asg5 application
*;
* @author
* @version 1.00 2007/9/24
*/
import java.util.*;
public class asg5 {
static Scanner console = new Scanner(System.in);
public static void main(String[] args) {
String line;
Boolean rev;
System.out.println("Enter a line of text 'q' to exit");
line = console.nextLine();
rev = recRev(line, 0);
}
public static Boolean recRev(String line, int pos){
int length, i;
char[] revline = new char[50];
length = line.length();
i=length - 1;
if (length>50)
{
return false;
}
if (pos<length)
{
revline[pos] = line.charAt(pos);
pos = pos + 1;
recRev(line, pos);
}else{
System.out.println(i);
while(i>=0)
{
System.out.print(revline[i]);
i--;
System.out.print(i);
}
}
return true;
}
}
eric
Comment