• 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;
    }
    }
  • 相关阅读:
    winfrom 对话框
    容器控件
    简单记事本整理
    公共控件
    winfrom。布局
    ado 小测试
    ado.not--更改精简练习
    ado.not--数据库防字符串注入攻击学习及 练习
    ado.not--练习题
    ado.not--添加练习题
  • 原文地址:https://www.cnblogs.com/rong123/p/9894462.html
Copyright © 2020-2023  润新知