码迷,mamicode.com
首页 > 其他好文 > 详细

反向输出字符串

时间:2017-08-23 14:54:34      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:for   main   str   public   bsp   int   oid   反向   hello   

//反向输出字符串
public class SwitchOne {

    public static void main(String[] args) {
        String aa= "hello";                  //字符串
        String [] bb=new String[aa.length()];//定义同等长度数组
        for(int i=1;i<=bb.length;i++){
            bb[i-1]=aa.substring(i-1,i);     //截取字符串的每一个字符,并赋值给数组元素
            System.out.print(bb[i-1]+" ");
        }
        System.out.println();
        System.out.println("*************************************");
        for(int j=1;j<=bb.length;j++){            //反向输出数组元素
            System.out.print(bb[bb.length-j]+" ");
        }
        
    }
    

}

 

反向输出字符串

标签:for   main   str   public   bsp   int   oid   反向   hello   

原文地址:http://www.cnblogs.com/-strong/p/7417873.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!