JAVA学习笔记:第二课时

package hello;//  包

import java.util.Scanner;//

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		System.out.println("Hello World");//输出
		Scanner in=new Scanner(System.in);//读用户输入
		
		//包裹的应用
		int k=10;
		Integer m=10;
		System.out.println(Integer.MAX_VALUE);//输出最大值
		System.out.println(Integer.MIN_VALUE);//输出最小值
		System.out.println(Character.isDigit('1'));//是否为数字字符
		System.out.println(Character.isLetter('l'));//是否为字符
		System.out.println(Character.isLetterOrDigit('?'));//输出最小值
		System.out.println(Character.toLowerCase('L'));//转换为小写字符
		
		//MATH类的应用
		System.out.println(Math.abs(-3));
		System.out.println(Math.round(10.453));
		System.out.println(Math.random()*100);//0到100的随机数
		System.out.println(Math.pow(2,3));
		
		//字符串的操作
		String s=new String("a");//管理者而不是所有者,string是一个类
		String h="hello";
		String sh=s+" "+h;
		System.out.println(sh+12+24);//自动类型转换
		
//		String str=in.next();//读入一个单词以空白字符为分格
//		String stl=in.nextLine();//读入一整行字符
//		System.out.println(str);
//		System.out.println(stl);
		
		//s=h;//s和h共同管理s所管理的字符串
		System.out.println(s=="hello");//比较是不是一个字符串,而不比较内容是否相等
		System.out.println(s.equals("hello"));//比较内容是否一致
		
		String p1="abc";
		String p2="0123456789abcd";
		System.out.println(p1.compareTo(p2));//比较字符串
		System.out.println(p1.length());//字符串长度
		System.out.println(p1.charAt(1));//获取字符串某位置上的字符
		
		System.out.println(p2.substring(2));//获得字串
		System.out.println(p2.substring(2,4));//从2开始到4之前为止   输出:23
		System.out.println(p2.indexOf('a'));//寻找字符,返回位置
		System.out.println(p2.indexOf("bcd"));//寻找字符串,返回位置
		System.out.println(p2.indexOf('0',2));//从2的位置找‘0’
		System.out.println(p2.lastIndexOf("bcd"));//反向查找
		System.out.println(p2.startsWith("0123"));//是否以“0123”开头
		System.out.println(p2.endsWith("abcd"));//是否以“abcd”结尾
		
		//以下不修改原字符串,无法改变
		s.trim();//删去字符串两端的空格
		s.toLowerCase();//全部变为小写
		System.out.println(p2.replace("abcd","1234"));//交换两个字符串
		
		
	}

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值