excuse me, simple question
I want a user to enter a string so that I may recursively call it to reverse it.
Just one thing, i wanna make sure the user did not enter a carriage return, if he/she did, it will loop and ask them to enter a string again. Basically error prevention. So I tried a while (x=="\n") or "" or "\r" where x is my string..it did not do anything. BTW i am using Eclipse.
So basically how can i do a loop in main that will keep asking user for a string and checking whether or not he enterd a "Enter"
Thanks ahead of time.
The prog:
**********************************
import java.io.*;
import java.util.Scanner;
public class stringreverse
{
public static void stringreversed(String s, int n)
{
if (n==0){
System.out.print("you entered nada");
return;}
else{
System.out.print(s.charAt(n-1));
stringreversed(s,n-1);
}
}
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.print("What do you want to reverse? ");
int t;
String x = scan.next();
while (x !="")
{
t = x.length();
stringreversed(x,t);
}
else
System.out.print("You entered an empty string,try again");
//want it to loop back to main here until a string is entered
}
}