JAVA的心动之旅

Day1 字符串String

1.0 字符串的特点以及创建一个字符串

public class Practice {//构建字符串的3+1种方法
public static void main(String[] args) {
//第一种
String one=new String();
System.out.println("输出的字符串为:"+one);
//第二种
char str[]={'A','B','C'};
String two=new String(str);
System.out.println("输出的字符串为:"+two);
//第三种
byte []bytes={97,98,99,100};
String three=new String(bytes);
System.out.println("输出的字符串为:"+three);
//+1种 直接构造 字符串常量不可改变
String four="HelloWorld";
System.out.println("输出的字符串为:"+four); }
}

打印结果:

输出的字符串为:
输出的字符串为:ABC
输出的字符串为:abcd
输出的字符串为:HelloWorld

2.0 字符串的常量池

3.0 字符串的获取方法

public class Practice {
public static void main(String[] args) {
String one="Hello";
System.out.println("字符串的长度为:"+one.length());
String two="say ".concat(one);
System.out.println("字符串为:"+two);
for(int i=0;i<two.length();i++)
{
char ch=two.charAt(i);
System.out.print(ch+" ");
}
String three="o";
System.out.println("\n"+one.indexOf(three));
String four="h";
System.out.println(one.indexOf(four));
}
}

打印结果

字符串的长度为:5
字符串为:say Hello
s a y H e l l o
4
-1

4.0 字符串的比较 ==为地址的比较

5.0 字符串的截取

public class Practice {
public static void main(String[] args) {
String one="hellobts";
String two=one.substring(5);
System.out.println(two);
String three=one.substring(0, 5);
System.out.println(three);
}
}

打印结果:

bts
hello

6.0 字符串的转化方法

public class Practice {
public static void main(String[] args) {
String one="hellobts";
char a[]=one.toCharArray();
for(int i=0;i<a.length;i++)
{
System.out.print(a[i]+" ");
}
System.out.println();
byte []bytes=one.getBytes();
for(int i=0;i<bytes.length;i++)
{
System.out.print(bytes[i]+" ");
}
System.out.println();
String two=one.replace("hello", "love");
System.out.println(two);
}
}

打印结果:

h e l l o b t s
104 101 108 108 111 98 116 115
lovebts

Day2 static 关键字

1.0 static 概述

一旦用了static 关键字,那么这样的内容不再属于对象自己,它是属于类的,所以凡是本类的对象,都共享一份。

2.0 static 修饰成员变量

public class Students {
private static int idcounter=0;//每当创建一个对象(new)计数器++
static String room;
private String name;
private int age;
private int id;
public Students() {
this.id=++idcounter;
}
public Students(String name, int age) {
this.name = name;
this.age = age;
this.id=++idcounter;
} 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 class Practice {
public static void main(String[] args) {
Students one=new Students("田小娟",22);
one.room="101教室";
Students two=new Students("徐穗珍",22);
System.out.println("姓名:"+one.getName()+" "+"年龄:"+one.getAge()+" 教室:"+one.room+
" 学号"+one.getId());
System.out.println("姓名:"+two.getName()+" "+"年龄:"+two.getAge()+" 教室:"+two.room+
" 学号"+two.getId());
}
}

3.0 static 修饰方法

4.0 静态代码块

Day3 与Arrays相识

1.0 简单的应用

import java.util.Arrays;

public class Practice {
public static void main(String[] args) {
int []num={3,89,45,235,43,79};
String str=Arrays.toString(num);
System.out.println(str);
Arrays.sort(num);
for(int i=0;i<num.length;i++)
{
System.out.print(num[i]+" ");
}
}
}

打印结果:

[3, 89, 45, 235, 43, 79]
3 43 45 79 89 235

2.0 字符串倒序

import java.util.Arrays;

public class Practice {
public static void main(String[] args) {
String str="aihfjsdfhuwefwnf";
//定义一个随机的字符串,并将字符串排序后倒序输出
//需将字符串先转化为字符数组,才能使用Arrays
char []chars=str.toCharArray();
Arrays.sort(chars);
for(int i=chars.length-1;i>=0;i--)
{
System.out.print(chars[i]+" ");//w w u s n j i h h f f f f e d a
} }
}

 Math类方法(百度)

最新文章

  1. LoadRunner --HTML/URL录制方式的选择规则
  2. 基于HT for Web的Web SCADA工控移动应用
  3. dedecms /include/filter.inc.php Local Variable Overriding
  4. c#之委托所有方法
  5. Android IOS WebRTC 音视频开发总结(十一)-- stun&amp;turn部署
  6. Laravel PHP Web开发框架
  7. 深入理解JS原型链与继承
  8. MSI文件静默安装
  9. 深入分析Java Web开发
  10. python2.x 使用protobuf
  11. 阿里的dubbo 到底是用来干嘛的?
  12. Linux配置浮动IP实现WEB高可用
  13. 初入红尘——在安联IT实习的一点感受(未完......)
  14. 初识mybatis(二)
  15. 电子产品使用感受之----AirPods的一天使用体验分享
  16. EL有11个隐含对象
  17. Python3学习笔记27-ConfigParser模块
  18. leetcode72
  19. ANDROID content provide 使用实例
  20. robots.txt、humans.txt、.editorconfig、.gitignore、LICENSE.txt、README.md、CHANGLOG.md

热门文章

  1. weak_ptr
  2. django3开发完整博客带评价
  3. 在Maven项目中添加代码目录下的配置文件
  4. 物流配送中心管理系统(SSM+MYSQL)
  5. [zoj3813]Alternating Sum 公式化简,线段树
  6. [hdu4300] next数组的应用
  7. JAVA实现拼手气红包算法
  8. .NET Core接入ElasticSearch 7.5
  9. vuecli3.x与vuecli2.x 主要区别
  10. Pytorch数据集读取