zoukankan      html  css  js  c++  java
  • Java-方法(新手)

    //创建的一个类。
    public class zy1ri0319 {
      //公共静态的主方法。
    public static void main(String[] args){
           //调用方法。
    zy1();
    zy2();
    zy3();
    zy4();
    zy5();
    zy6();
    zy7();
    }
      //创建方法
      //选取下标为5的字符。
      //关键词-char charAt(int index);
    public static void zy1(){
    String s = "sdfasg";
    char s1 = s.charAt(5);
    System.out.println(s1);
    }
    打印结果:
      g
    =======================================================

      //创建方法。
      //把大写字符改为小写字符。(substring里的0,3为索引字符下标,含头不含尾)
      //关键词-String toLowerCase();
    public static void zy2(){
    String s = "ARR";
    String s1 = s.substring(0,3);
    String S1 = s1.toLowerCase();
    System.out.println(S1);
    }
    打印结果:
      arr
    ======================================================

      //创建方法。
      //把小写字符改变为大写。(substring里的0,3为索引字符下标,含头不含尾)
      //关键词-String toUpperCase();
        public static void zy3(){
    String s = "arr";
    String s1 = s.substring(0,3);
    String S1 = s1.toUpperCase();
    System.out.println(S1);
    }
    打印结果:
      Arr
    ======================================================

      //创建方法。
      //把字符里的老字符替换为新字符(r为老字符,t为新字符。)
      //关键词-String repalce(char oldChar, char newChar);
    public static void zy4(){
    String s = "Arrsrtl";
    String S1 = s.replace('r','t');
    System.out.println(S1);
    }

    打印结果:
      Attsttl
    ======================================================
      //创建方法。
      //将字符串中的老字符串,替换为新字符串。(ss为老字符串,rt为新字符串)
      //关键词-String repalce(String old, String newstr);
    public static void zy5(){
    String s = "Assretl";
    String S1 = s.replace("ss","rt");
    System.out.println(S1);
    }
    打印结果:
      Artretl
    ======================================================
      //创建方法。
      //String trim(): 去掉字符串两端空格
    public static void zy6(){
    String s = " asdfasf ";
    String S1 = s.trim();
    System.out.println(S1);
    }
    打印结果:
      asdfasf
    ======================================================
      //创建方法。
      //判断字符串是不是空串,如果是空的就返回true。
      //关键词-boolean isEmpty();
    public static void zy7(){
    String s = new String();
    //若是空则为真,否为假(isEmpty 空的)
    boolean b = s.isEmpty();
    System.out.println(b);
    }
    }
  • 相关阅读:
    0Day – 2011.01.26
    JQuery_PHP 开始新的旅途
    0Day – 2011.01.25
    0Day – 2011.02.04
    Delphi 必须的一致.
    0Day – 2011.01.28
    0Day – 2011.02.23[From B4A]
    足球 看球悲惨的回忆.
    Delphi – EurekaLog6.1.01Ent下载地址
    ubuntu 拨号
  • 原文地址:https://www.cnblogs.com/lxr521/p/10561737.html
Copyright © 2011-2022 走看看