十七次

package day17_code;
/*
 * 
 * String 类代表字符串。JAVA程序中的所有字符串字面值(如"abc")都作为此类的实例实现。
 * 就是说"abc"都是String类的对象
 * 
 * 
 *字符串的特点:
 *1.字符串的内容永不可变(重点)
 *2.字符串是可以共享使用
 *3.字符串效果上是相当于一个char[],但是实际底层储存的是byte[] 
 * 
 * 常用的三种构造方法
 * 1.public Strig()创建一个空白的字符串,不包含任何内容
 * 2.public String(char[]array)根据字符数组来创建对象
 * 3.public String(char byte[]array)根据字符数组来创建对象
 * 
 */
public class Demo01String {
    public static void main(String[]args) {
    	String str1= new String();//小括号留空,没有内容
    	System.out.println("第一个字符串:"+str1);
    	
    	
    	System.out.println("=========");
    	char[] chararray= {'a','b','c','d'};
    	System.out.println(chararray);
    	String str2=new String(chararray);
    	System.out.println(str2);
    	
    	System.out.println("=========");
    	byte[] bytearray= {97,98,99};
    	System.out.println(chararray);
    	String str3=new String(chararray);
    	System.out.println(str3);
    	
    	
    	//string str4=new
    	String str4="class5";
    	System.out.println(str4);
    }
}

![在这里插入图片描述](https://img-blog.csdnimg.cn/20210506192513369.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzU1Njg5MzE4,size_16,color_FFFFFF,t_70#pic_center)
 package day17_code;

public class Demo02StringPoo {
	public static void main(String[]args) {
	
	String str1="abc";
	String str2="abc";
	
	char[] chararray= {'a','b','c','d'};
	String str3=new String(chararray);
	
	System.out.println(str1=str2);
	System.out.println(str1=str3);
	System.out.println(str2=str3);
	
	str2="code";
	System.out.println(str2);
}
}
 
  ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210506192640849.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzU1Njg5MzE4,size_16,color_FFFFFF,t_70#pic_center)
 package demo02;

public class Demo02StringEquals {
	public static void main(String[]args) {
		
		String str1="Hello";
		String str2="Hello";
		System.out.println(str2);
		char[] chararray= {'H','e','l','l','o'};
		String str3=new String(chararray);
		
		System.out.println(str1.equals(str2));
		System.out.println(str2.equals(str3));
		System.out.println(str1.equals(str3));
		
		System.out.println(str1.equals("Hello"));
		
		System.out.println("Hello".equals(str1));
		
		System.out.println("=========");
		String str4=null;
		
		System.out.println("Hello".equals(str4));
		System.out.println("=========");
		String str5="Hello";
		System.out.println("Hello".equals(str4));
		
}
}
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210506192809971.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzU1Njg5MzE4,size_16,color_FFFFFF,t_70)
 package demo02;

public class Demo02StringGet {
	public static void main(String[]args) {
		//1.字符串长度
		int length="agebagfdygdszhhsbhsbbbdb".length();
		System.out.println("字符串长度"+length);
		
		
		
		//.2字符串拼接
		String str1="Hello";
		String str2="class5";
		String str3=str1.concat(str2);
		System.out.println(str1);//Hello
		System.out.println(str2);//class5
		System.out.println(str1);//Helloclass5 重新创建一个字符串,并不是在原来字符串上进行修改
		
		//3.获得指定索引位置的单个字符
		
		char ch="Hello".charAt(4);
		System.out.println("0号索引位置1的字符是;"+ch);
		
		String orignal="HelloWorldHelloWorldHelloWorld";
		int index=orignal.indexOf("llo");
		System.out.println(index);
		System.out.println(orignal.indexOf("class"));
		
		
	}
}
 package demo02;
/*
 * 
 * 
 * 
 * 分割字符串
 * public string[] split (string)
 */
public class Demo02StringSplit {
	public static void main(String[]args) {
		String str1="aaa,bbb,ccc";
		String[] array1=str1.split(",");
		for(int i=0;i<array1.length;i++) {
			System.out.println(array1[i]);
		}
	}
}
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210506193212293.PNG#pic_center)
 package demo02;

public class Demo03SubString {
	public static void main(String[]args) {
		
		String str1="HelloClass5";
		String str2=str1.substring(5);
		System.out.println(str1);
		System.out.println(str2);
		
		String str3=str1.substring(2,5);
		System.out.println(str3);
		
	}
}
 package demo03;

public class Demo03Math {
	public static void main(String[]args) {
		System.out.println(Math.abs(3.14));
		System.out.println(Math.abs(0));
		System.out.println(Math.abs(-3.14));
		System.out.println("========");
		
		
		
		System.out.println(Math.ceil(3.91));
		System.out.println(Math.ceil(3.5));
		System.out.println(Math.ceil(3.00001));
		System.out.println("=======");
		
		
		System.out.println(Math.floor(3.14));
		System.out.println(Math.floor(3.5));
		System.out.println(Math.floor(3.00001));
		System.out.println("=======");
		System.out.println(Math.ceil(3.5));
		System.out.println(Math.ceil(3.00001));
		System.out.println("=======");
		
		System.out.println(Math.round(20.4));
		System.out.println(Math.round(20.5));
		System.out.println("=======");
	}
}
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210506193347878.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzU1Njg5MzE4,size_16,color_FFFFFF,t_70#pic_center)
 package demo03;

import java.util.Arrays;

public class Demo03Arrays {
	public static void main(String[]args) {
		int [] intArray= {10,20,30};
		System.out.println(intArray);
		
		String intStr=Arrays.toString(intArray);
		System.out.println(intStr);
		
		int[] array1= {3,3,5,7,9,5,6};
		System.out.println(Arrays.toString(array1));
		Arrays.sort(array1);
		System.out.println(Arrays.toString(array1));
		
		String[] array2= {"ddd","aaa","kkk"};
		Arrays.sort(array2);
		System.out.println(Arrays.toString(array2));
	}
		
	}

 package demo04;

public class Student {
private int id;
private  String name;
private int age;
private static String room;
public int getId() {
	return id;
}
public void setId(int id) {
	this.id = id;
}
public String getName() {
	return name;
}
public void setName(String name) {
	this.name = name;
}
public int getAge() {
	return age;
}
public void setAge(int age) {
	this.age = age;
}
public static String getRoom() {
	return room;
}
public static void setRoom(String room) {
	Student.room = room;
}
public Student(String name, int age) {
	super();
	this.name = name;
	this.age = age;
}
public Student() {
	super();
	
}



}
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210506193521313.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzU1Njg5MzE4,size_16,color_FFFFFF,t_70#pic_center)
 package demo04;

public class MyClass {
int num;
static int numstatic;


public void method() {
	System.out.println("这是成员方法");
}


public static void methodStatic() {
	System.out.println("这是静态方法");
	}
}
package demo04;

public class Demo04StaticMethod {
	public static void main(String[]args) {
		MyClass obj=new MyClass();
		obj.method();
		
		MyClass.methodStatic();
		MyClass.methodStatic();
	}
}

![在这里插入图片描述](https://img-blog.csdnimg.cn/2021050619380941.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzU1Njg5MzE4,size_16,color_FFFFFF,t_70#pic_center)


 package demo04;

public class Demo04StaticFiled {
	public static void main(String[]args) {
		Student one=new Student("郭靖",19);
		one.setRoom("3306教室");
		
		System.out.println(one.getName()+"   "+one.getAge()+"   "+one.getRoom());
		Student two=new Student("黄蓉",16);
		System.out.println(two.getName()+"   "+two.getAge()+"   "+two.getRoom());
	}
}
 ![在这里插入图片描述](https://img-blog.csdnimg.cn/20210506193637949.PNG?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L20wXzU1Njg5MzE4,size_16,color_FFFFFF,t_70#pic_center)
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值