zoukankan      html  css  js  c++  java
  • String普通方法测试;可变参数

    String几种普通方法的测试:

    public class Ceshisizhui {
        public static void main(String[] args) {
            String str="912,21231,32423,65";
            String[] strs=str.split(",");
            System.out.println(strs[2]);//输出拆分后字符串数组索引为2的字符串
            System.out.println(str.charAt(6));//输出字符串str索引为6的字符
            System.out.println(str.indexOf("21"));//输出制定字符串在此字符串中第一次出现处的索引
            System.out.println(str.contains("656"));//判断字符串是否包含该字符
            
        }
    }

    输出结果:

    可变参数:

    public class Kebiancanshu {
        public static void main(String[] args) {
            int[] ins=new int[]{1,2,4,5};
            System.out.println(add(ins));
        }
        public static int add(int...xyz){
            int sum=0;
            for(int i=0;i<xyz.length;i++){
                sum+=xyz[i];
            }
            return sum;
        }
    }
  • 相关阅读:
    Vue单向数据流
    npm常用命令
    vue自定义指令
    slot的用法(Vue插槽)
    js闭包
    canvas 给画的多边形着色
    canvas画线
    canvas初体验
    canvas
    json
  • 原文地址:https://www.cnblogs.com/FrankLiner/p/7609235.html
Copyright © 2011-2022 走看看