我需要遍历字符串userInput并查找char是字母还是数字,如果是,则需要将该char附加到String endProduct。
public static String converter(String userInput) {
String endProduct = "";
char c = userInput.charAt(0);
Stack<Character> stack = new Stack<Character>();
int len = userInput.length();
//iterates through the word to find symbols and letters, if letter or digit it appends to endProduct, if symbol it pushes onto stack
for (int i = c; i < len; i++) {
if (Character.isLetter(userInput.charAt(i))) {
endProduct = endProduct + c;
System.out.println(c);
}//end if
else if(Character.isDigit(userInput.charAt(i))){
endProduct = endProduct + c;
System.out.println(c);
}
public static String converter(String userInput) {
String endProduct = "";
Stack<Character> stack = new Stack<Character>();
int len = userInput.length();
//iterates through the word to find symbols and letters, if letter or digit it appends to endProduct, if symbol it pushes onto stack
for (int i = 0; i < len; i++) {
char c = userInput.charAt(i);
if (Character.isLetter(userInput.charAt(i))) {
endProduct = endProduct + c;
System.out.println(c);
}//end if
else if (Character.isDigit(userInput.charAt(i))) {
endProduct = endProduct + c;
System.out.println(c);
}
// Push to stack if char c is not letter or digit
else {
stack.push(c);
}
}
System.out.println(endProduct);
return endProduct;
}