zoukankan      html  css  js  c++  java
  • string倒序输出(四种方法)

    package com.string.domain;

    public class Test1 {

        //方法一
        /*public static void main(String[] args) {
            String names = "asdfghjkl74108520963";
            for (int i = names.length(); i > 0; i--) {
                System.out.print(names.charAt(i - 1));
            }
        }*/
        //方法二
        /*public static String ZXK = "iniaow4131";
        
        public static String descString(String zxk) {
            if(zxk == null || zxk.length() < 0 ){
                return "error";
            }
            byte[] bytes = zxk.getBytes();
            for (int i = 0; i < bytes.length/2; i++) {
                byte b = bytes[i];
                bytes[i] = bytes[bytes.length - i - 1];
                bytes[bytes.length - i - 1] = b;
            }
            return new String(bytes);
        }
        public static void main(String[] args) {
            System.out.println(descString(ZXK));
        }*/
        //方法三
        /*public static void main(String[] args) {
            String originalString = "abcdefg";  
                String resultString = "";  
                char[] charArray = originalString.toCharArray();  
                for (int i = charArray.length-1; i>=0; i--){  
                      resultString +=charArray[i];  
                 }  
              System.out.println(resultString);  
        }*/
        
        //方法四
        public static void main(String[] args) {
            String zxk = "asdfghjk";
            StringBuffer sb = new StringBuffer(zxk);
            System.out.println(sb.reverse());
        }
    }

  • 相关阅读:
    C语言的数组
    C语言的组成 以及预编译
    python实战——网络爬虫之request
    python实战——网络爬虫
    web渗透-sqli-labs-master 下载与安装
    PHP之旅4 php 超全局变量
    PHP之旅9 MySQL数据库
    PHP之旅8 URL与表单
    mysql数据库事务隔离级别与设置
    xsell 过期后的处理方法
  • 原文地址:https://www.cnblogs.com/Angel-Mary/p/6111186.html
Copyright © 2011-2022 走看看