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);
}
}
posted @ 2019-03-19 21:59 浪子。 阅读( ...) 评论( ...) 编辑 收藏
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值