-
public class Test {
-
public String getReturnNum(String num){ StringBuffer sb = new StringBuffer(); while(num.length() > 0 ){ sb.append(num.charAt(num.length() - 1 )); num = (String) num.subSequence(0, num.length() - 1 ); } return sb.toString(); } public static void main(String[] args) { Test t = new Test(); String num = "478.abc" ; System.out.println(t.getReturnNum(num)); } }
打印结果:cba.874 -
如果不明白,可以单独测试String的下面几个方法就明白了:
-
charAt(int i);
-
subSequence(int begin, int end);
倒序输出一组字符串。例如输入:“478.abc”,输出:“cba.874”
最新推荐文章于 2023-04-26 21:41:15 发布