题解 | #字符串反转#
字符串反转
https://www.nowcoder.com/practice/e45e078701ab4e4cb49393ae30f1bb04
import java.util.*; public class Main { public static void main(String[] args) { Scanner fzhinput = new Scanner(System.in); String sr = fzhinput.nextLine(); StringBuilder stack = new StringBuilder(); int i; boolean pd = true; for(i=sr.length()-1; i>=0;i--){ char c = sr.charAt(i); if(Character.isLowerCase(c)){ pd = true; } else{ System.out.println("只接受全是小写字母的字符串"); pd = false; break; } } if( pd ){ for(i=sr.length()-1; i>=0;i--){ char c = sr.charAt(i); stack.append(c); } } else{ stack.setLength(0); } System.out.println(stack); } }