我的程序应该根据用户的输入生成字母模式。我必须使用递归将每个输出设置为不同的。我已经这样做了。接下来我必须用另一种方法比较两个输出,并使用递归来找到两者之间最长的公共子序列的长度。问题是我不知道如何比较它们。由于它们是无效的结果,我不知道如何将它们转换为字符串。
import java.util.Scanner;
public class patternOfLetters {
private static String letter;
public static void printLetterPattern(char letter){
char [] pattern = new char[1];
int patternLength= pattern.length;
String result="";
char start=letter;
if(start=='A'){
System.out.print('A');
result+='A';
}else if(start=='B'){
printLetterPattern('A');
System.out.print('B');
printLetterPattern('A');
}
else if(start=='C'){
printLetterPattern('B');
System.out.print('C');
printLetterPattern('B');
}
else if(start=='D'){
printLetterPattern('C');
System.out.print('D');
printLetterPattern('C');
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
Scanner otherIn = new Scanner(System.in);
System.out.println("Enter a character to start the pattern: ");
String input = in.nextLine();
String upper = input.toUpperCase();
char letter=upper.charAt(0);
System.out.println("");
System.out.println("Your first pattern of letters is:");
printLetterPattern(letter);
System.out.println("");
System.out.println("");
System.out.println("Enter another character to generate your second pattern: ");
String input2 = in.nextLine();
String upper2 = input2.toUpperCase();
char letter2=upper2.charAt(0);
System.out.println("");
System.out.println("Your second pattern of letters is:");
printLetterPattern(letter2);
in.close();
otherIn.close();
}
}//鳍。