java学习笔记+小程序练习第一期

今日学习:数学函数,子串的提取、连接。

1.数学函数sqrt,pow
public class DoubleYs {
public static void main(String []args) {
double x = 4;
double y = Math.sqrt(x);
double z = Math.pow(x,2);
System.out.println(y);
System.out.println(z);
}
}

2.子串提取
String类的substring方法可以从长的子串中提取比较短的子串

public class Zichuan {
public static void main(String []args) {
String greeting = “hello”;
String s = greeting.substring(0,3); //提取短的子串,提取0,1,2三个位置的值
System.out.println(s);
// System.out.println(z);
}
}
结果:hel

3.两个字符串连接 :用“+”即可实现
public class Zichuan_lj {
public static void main(String []args) {
String str1 = “hello”;
String str2 = " word!";
String s = str1 + str2 ; //连接两个子串
System.out.println(s);
// System.out.println(z);
}
}

4.检测两个字符串是否相等
用equals方法来检测
s.equals(t)来比较子串s和t

5.子串的长度
public class Length_zf {
public static void main(String []args) {
String str1 = “hello”;
// String str2 = " hello";
int n = str1.length(); //结果为5
int cpCount = str1.codePointCount(0,str1.length()); //实际长度,也是代码点数量
System.out.println(n);
System.out.println(cpCount);
}
}
其它知识点,先记录下来:
02

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值