import java.util.*;
public class RecursionProject {
public static void main(String[]args) {
getLine();
useRecursion();
}
public static void getLine() {
System.out.println("This program uses recursion.") ;
System.out.println("Would you like to see how it works?") ;
System.out.print("If yes, type yes, else type no -----> ");
String userResponse = null;
Scanner in = new Scanner(System.in);
userResponse = in.next();
System.out.println(userResponse);
if (userResponse.equalsIgnoreCase("yes")) {
System.out.println() ;
}
else {
System.out.println("Thank you for using this program.");
System.exit(0);
}
}
private static void useRecursion(){
System.out.println("Type in what you would like to see") ;
System.out.println("done recursively. (This program ") ;
System.out.println("excludes white spaces):") ;
String s = null ;
Scanner console = new Scanner(System.in) ;
s = console.next() ;
if (s.isEmpty()) {
System.out.print(" - ") ;
}
else {
System.out.println("0") ;
}
}
}
所以这是我到目前为止的代码。我的任务是从控制台读取输入,然后使用递归反转相位。即,如果用户键入“动物”,它会在屏幕上打印出“slamina”。我知道我的基本情况是该行是否为空,而我的递归情况是该行是否包含文本。这是一个 Programming 2 类,在 Eclipse 4.2.2 上使用 Java