zoukankan      html  css  js  c++  java
  • StringDemo5

    package cn.zuoye;
    import java.util.Scanner;

    /*  字符串反转
     * 举例:录入:123
     * 输出:321
     *
     * 分析:键盘录入
     *   定义一个新字符串
     *   倒着遍历字符串,得到每个字符串
     *   用新字符串把每一个字符拼接起来
     *   输出
     *
     */
    public class StringDemo5 {
     public static void main(String[] args) {
      // 键盘录入
      Scanner sc = new Scanner(System.in);
      System.out.println("请输入一个字符串:");
      String line = sc.nextLine();
      String ss= StringDemo5.Myrr(line);
      System.out.println(ss);
      /*// 定义一个新字符串
      String result = "";
      // 字符串转换成字符数组
      char[] chs = line.toCharArray();
      
      //倒着遍历字符串,得到每个字符串
      for(int x=chs.length-1;x>=0;x--){
       //用新字符把每一个字符拼接起来
       result +=chs[x];
      }*/
      //输出
     // System.out.println(result);
      
     //功能版
     /*
      * 返回值:String
      * 参数类型:String 
      */
     
    }
     public static String Myrr(String s){
      String result = "";
      // 字符串转换成字符数组
      char[] chs = s.toCharArray();
      
      //倒着遍历字符串,得到每个字符串
      for(int x=chs.length-1;x>=0;x--){
       //用新字符把每一个字符拼接起来
       result +=chs[x];
      } 
      return result;
    }
    }
  • 相关阅读:
    POJ 3009 Curling 2.0 简单DFS 好题
    POJ 3253 Fence Repair 贪心
    python_13 面向对象
    python_12 模块
    python练习题_04
    python_11 装饰器,闭包
    python练习题_03
    python_10 迭代器和生成器
    python_09 文件处理流程,文件操作方法
    python_08 函数式编程、高阶函数、map、filter、reduce函数、内置函数
  • 原文地址:https://www.cnblogs.com/rong123/p/9894462.html
Copyright © 2011-2022 走看看